ASP.NET Web Services. A unit of managed code installed under IIS that can be remotely invoked using...
-
Upload
sherilyn-turner -
Category
Documents
-
view
219 -
download
0
Transcript of ASP.NET Web Services. A unit of managed code installed under IIS that can be remotely invoked using...
ASP.NET ASP.NET
Web ServicesWeb Services
Web ServicesWeb Services
A unit of managed code installed under IIS A unit of managed code installed under IIS that can be remotely invoked using HTTP.that can be remotely invoked using HTTP.
Similar TechnologiesSimilar Technologies
DCOMDCOM CORBACORBA EJB (Enterprise Java Beans)EJB (Enterprise Java Beans)
All are tied to a specific language or a All are tied to a specific language or a proprietary protocol.proprietary protocol.
Introducing Web ServicesIntroducing Web Services
Language Agnostic.Language Agnostic. Can be called by any program that can Can be called by any program that can
parse XML and use HTTP.parse XML and use HTTP. Can be called from Web Forms as well as Can be called from Web Forms as well as
Windows Forms.Windows Forms.
Supporting TechnologiesSupporting Technologies
Web Service Description Language (WSDL)Web Service Description Language (WSDL) A wire protocol (HTTP GET, HTTP POST, or SOAP)A wire protocol (HTTP GET, HTTP POST, or SOAP) A discovery Service (*.disco files)A discovery Service (*.disco files) ProxiesProxies IISIIS
Building a Simple Web ServiceBuilding a Simple Web Service
Select C# Projects->ASP.NET Web Service.Select C# Projects->ASP.NET Web Service. Automatically creates a virtual directory Automatically creates a virtual directory
under IIS.under IIS. Can test from within the program without Can test from within the program without
using a client.using a client.
WebService Base ClassWebService Base Class
Not required to derive from this class, can inherit Not required to derive from this class, can inherit directly from object.directly from object.
Adds functionality such that a web service can Adds functionality such that a web service can interact with the same types used by the ASP.NET interact with the same types used by the ASP.NET object model:object model:– Application ObjectApplication Object– Context ObjectContext Object– Server ObjectServer Object– Session ObjectSession Object– User ObjectUser Object
WSDLWSDL
WWeb eb SService ervice DDescription escription LLanguageanguage Contract between the client and the web Contract between the client and the web
service, that defines the interactionservice, that defines the interaction– Function names.Function names.– Parameters and their types.Parameters and their types.– Syntax of various wire protocols.Syntax of various wire protocols.
System.Web.Services.Description contains System.Web.Services.Description contains types that allow you to programmatically types that allow you to programmatically manipulate the WSDL.manipulate the WSDL.
SOAPSOAP
Simple Object Access ProtocolSimple Object Access Protocol XML BasedXML Based TypesTypes
– ADO.NET DataSetsADO.NET DataSets– Complex ArraysComplex Arrays– Custom TypesCustom Types
Binding:Binding:</binding></binding> <service name="<service name="HPSIClaimServicesHPSIClaimServices">"> <port name="<port name="HPSIClaimServicesSoapHPSIClaimServicesSoap" binding="" binding="s0:HPSIClaimServicesSoaps0:HPSIClaimServicesSoap">">
<soap:address location="<soap:address location="http://localhost/HPSIClaimServices/HPSIClaimServices.asmxhttp://localhost/HPSIClaimServices/HPSIClaimServices.asmx" /> " /> </port></port> </service></service>
ProxiesProxies
Creates a class that contains the interface for your Creates a class that contains the interface for your web serviceweb service
Using wsdl.exeUsing wsdl.exeC:\wsdl.exe out:c:\testproxy.csC:\wsdl.exe out:c:\testproxy.cshttp://localhost/testwebservice/text.asmx?wsdlhttp://localhost/testwebservice/text.asmx?wsdl
Using Visual Studio .NETUsing Visual Studio .NET– Add Web ReferenceAdd Web Reference
ProxiesProxies
Adds Asynchronous and Synchronous Adds Asynchronous and Synchronous versions of each exposed Web Methodversions of each exposed Web Method
Looks and feels like the Web Service is a Looks and feels like the Web Service is a class in the client applicationclass in the client application
AdvancedAdvanced
Serializing Custom TypesSerializing Custom Types Using Session to maintain information from Using Session to maintain information from
previous callsprevious calls Connecting to a Database Connecting to a Database
Serializing Custom TypesSerializing Custom Typesusing System;using System;using System.Xml.Serialization;using System.Xml.Serialization;
namespace CarsWebServicenamespace CarsWebService{{ //Tells the serializer to generate the proper XML tags for a car//Tells the serializer to generate the proper XML tags for a car typetype [XmlInclude(typeof(Car))] [XmlInclude(typeof(Car))] public class Carpublic class Car {{ public string name;public string name; public int maxSpeed;public int maxSpeed; public Car(){}public Car(){} public Car(string n, int s)public Car(string n, int s) {{ name = n;name = n; maxSpeed = s;maxSpeed = s; }} }}}}
//The XML Serializer will only serialize public members or properties that expose //The XML Serializer will only serialize public members or properties that expose those membersthose members
Session StateSession Statenamespace TestServicenamespace TestService{{
public class TestService1 : public class TestService1 : System.Web.WebServiceSystem.Web.WebService{{
public TestService1()public TestService1(){{
InitializeComponent();InitializeComponent();Session.Add(“TestDataSet”, null);Session.Add(“TestDataSet”, null);
}}
[WebMethod][WebMethod]public void TestMethod(DataSet ds)public void TestMethod(DataSet ds){{
Session[“TestDataSet”] = ds;Session[“TestDataSet”] = ds;}}
}}}}
Database ConnectionsDatabase Connections
Allows for Database client software to reside on one Allows for Database client software to reside on one machine.machine.
Allows for one consistent interface to the database.Allows for one consistent interface to the database.
Allows the business rules to be separate from the clientAllows the business rules to be separate from the client
Discovery Service ProtocolDiscovery Service Protocol Describes each Web Service in a given virtual directory.Describes each Web Service in a given virtual directory. .disco file is part of the client project.disco file is part of the client project C:\disco <URL for .disco file>C:\disco <URL for .disco file>
<?xml version="1.0" encoding="utf-8"?><discovery xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.xmlsoap.org/disco/"> <contractRef ref="http://161.28.113.202/HPSIBuildRunServices/BuildRunService.asmx?wsdl" docRef="http://161.28.113.202/HPSIBuildRunServices/BuildRunService.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> <soap address="http://161.28.113.202/HPSIBuildRunServices/BuildRunService.asmx" xmlns:q1="hpsiserver.hpsionline.com" binding="q1:BuildRunServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" /></discovery>
Distributing over a networkDistributing over a network
DatabaseWeb
Service
WebForm
WindowsForm
Creating a Web Service ProjectCreating a Web Service Project
Choose ASP.NET Web ServiceChoose ASP.NET Web Service The project is created in C:\Inetpub\The project is created in C:\Inetpub\
wwwroot\projectnamewwwroot\projectname The web service file is .asmxThe web service file is .asmx
– Code behind is in .asmx.cs fileCode behind is in .asmx.cs file
IIS must be installedIIS must be installed
Using a Web ServiceUsing a Web Service
Add a web referenceAdd a web reference– The proxy is hidden in the Web Reference The proxy is hidden in the Web Reference
Create an instance of the proxy classCreate an instance of the proxy class Use the proxy instance as you would a Use the proxy instance as you would a
normal class instancenormal class instance
ConclusionConclusion
Web Services are cool!Web Services are cool! Can be used to allow dissimilar systems to Can be used to allow dissimilar systems to
communicatecommunicate Easy to implementEasy to implement Easy to learn how to useEasy to learn how to use Fairly SlowFairly Slow