1 / 20

ASP.NET

ASP.NET. Web Services. Web Services. A unit of managed code installed under IIS that can be remotely invoked using HTTP. Similar Technologies. DCOM CORBA EJB (Enterprise Java Beans) All are tied to a specific language or a proprietary protocol. Introducing Web Services.

geri
Download Presentation

ASP.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.NET Web Services

  2. Web Services • 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. 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

  8. 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.

  9. SOAP • Simple Object Access Protocol • XML Based • Types • ADO.NET DataSets • Complex Arrays • Custom Types • Binding: </binding> <service name="HPSIClaimServices"> <port name="HPSIClaimServicesSoap" binding="s0:HPSIClaimServicesSoap"> <soap:address location="http://localhost/HPSIClaimServices/HPSIClaimServices.asmx" /> </port> </service>

  10. 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

  11. 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

  12. Advanced • Serializing Custom Types • Using Session to maintain information from previous calls • Connecting to a Database

  13. Serializing Custom Types using System; using System.Xml.Serialization; namespace CarsWebService { //Tells the serializer to generate the proper XML tags for a cartype [XmlInclude(typeof(Car))] public class Car { public string name; public int maxSpeed; public Car(){} public Car(string n, int s) { name = n; maxSpeed = s; } } } //The XML Serializer will only serialize public members or properties that expose those members

  14. 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; } } }

  15. 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

  16. Discovery Service Protocol • Describes each Web Service in a given virtual directory. • .disco file is part of the client project • 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>

  17. Distributing over a network Web Form SQL Database Web Service SOAP Windows Form

  18. 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

  19. 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

  20. 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

More Related