Download presentation
Presentation is loading. Please wait.
Published bySherilyn Turner Modified over 9 years ago
1
ASP.NET Web Services
2
A unit of managed code installed under IIS that can be remotely invoked using HTTP.
3
Similar Technologies DCOM CORBA EJB (Enterprise Java Beans) All are tied to a specific language or a proprietary protocol.
4
Introducing Web Services Language Agnostic. Can be called by any program that can parse XML and use HTTP. Can be called from Web Forms as well as Windows Forms.
5
Supporting Technologies Web Service Description Language (WSDL) A wire protocol (HTTP GET, HTTP POST, or SOAP) A discovery Service (*.disco files) Proxies IIS
6
Building a Simple Web Service Select C# Projects->ASP.NET Web Service. Automatically creates a virtual directory under IIS. Can test from within the program without using a client.
7
[WebMethod] Attribute This attribute must be applied to each method you wish to expose to the outside world through HTTP. May have optional parameters such as: –Description –EnableSessionn (false by default) –MessageName Adds a description to the WSDL Contract. [WebMethod(Description=“Returns an integer between 0 and the parameter”)] public int ReturnAnInt (int MaxValue) { return new Random().Next(MaxValue); }
8
WebService Base Class Not required to derive from this class, can inherit directly from object. Adds functionality such that a web service can interact with the same types used by the ASP.NET object model: –Application Object –Context Object –Server Object –Session Object –User Object
9
WSDL Web Service Description Language Contract between the client and the web service, that defines the interaction –Function names. –Parameters and their types. –Syntax of various wire protocols. System.Web.Services.Description contains types that allow you to programmatically manipulate the WSDL.
10
SOAP Simple Object Access Protocol XML Based Types –ADO.NET DataSets –Complex Arrays –Custom Types Binding: </binding>
11
Proxies Creates a class that contains the interface for your web service Using wsdl.exe C:\wsdl.exe out:c:\testproxy.cs http://localhost/testwebservice/text.asmx?wsdl Using Visual Studio.NET –Add Web Reference
12
Proxies Adds Asynchronous and Synchronous versions of each exposed Web Method Looks and feels like the Web Service is a class in the client application
13
Advanced Serializing Custom Types Using Session to maintain information from previous calls Connecting to a Database
14
Serializing Custom Types using System; using System.Xml.Serialization; namespace CarsWebService { //Tells the serializer to generate the proper XML tags for a car type //Tells the serializer to generate the proper XML tags for a car type [XmlInclude(typeof(Car))] [XmlInclude(typeof(Car))] public class Car public 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 those members
15
Session State namespace TestService { public class TestService1 : System.Web.WebService { public TestService1() {InitializeComponent(); Session.Add(“TestDataSet”, null); }[WebMethod] public void TestMethod(DataSet ds) { Session[“TestDataSet”] = ds; }}}
16
Database Connections Allows for Database client software to reside on one machine. Allows for one consistent interface to the database. Allows the business rules to be separate from the client
17
Discovery Service Protocol Describes each Web Service in a given virtual directory. .disco file is part of the client project C:\disco C:\disco <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/" />
18
Distributing over a network Database Web Service Web Form Windows Form
19
Creating a Web Service Project Choose ASP.NET Web Service The project is created in C:\Inetpub\wwwroot\projectname The web service file is.asmx –Code behind is in.asmx.cs file IIS must be installed
20
Using a Web Service Add a web reference –The proxy is hidden in the Web Reference Create an instance of the proxy class Use the proxy instance as you would a normal class instance
21
Conclusion Web Services are cool! Can be used to allow dissimilar systems to communicate Easy to implement Easy to learn how to use Fairly Slow
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.