1 / 15

Web Services Introduction

Web Services Introduction. ISYS 546. Web Service. XML Web Service Web services are classes that are stored on the web which can instantiate and use in both Windows and Web applications. Creating a Web Service Using a Text Editor. WebService directive: <%@ WebService Class="CustomerInfo" %>

charo
Download Presentation

Web Services Introduction

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. Web Services Introduction ISYS 546

  2. Web Service • XML Web Service • Web services are classes that are stored on the web which can instantiate and use in both Windows and Web applications.

  3. Creating a Web Service Using a Text Editor • WebService directive: • <%@ WebService Class="CustomerInfo" %> • Import namespaces: • imports System.Web.Services • imports System • Define the web service class. • Add WebMethod attribute to the function declaration. • Note: Web service file extension is ASMX

  4. A Web Service ExampleASPET/TestWebService.ASMX <%@ WebService Class="CustomerInfo" %> imports System.Web.Services imports System imports System.Data imports System.Data.Oledb Public Class CustomerInfo <webMethod()> public Function GetCname(ByVal CID as String) as String dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" dim objConn as new OledbConnection(strConn) dim strSQL as string = "select * from customer where CID = '" & CID & "';" dim objComm as new OledbCommand(strSQL,objConn) dim Results as string objConn.open() dim objDataReader as oledbDataReader objDataReader=objComm.executeReader() objDataReader.read() return objDataReader("Cname") end function

  5. Creating a Web Service Using VS • New Project/ASP.Net Web Service

  6. Web Service Description Language (WSDL) • A WSDL file is an XML document containing a complete description of the web service. It shows a web service’s name, methods, and parameter types. • Help page: After entering web service’s URL, a help page is displayed. You can click the Service Description link to see the WSDL file.

  7. HTTP • HTTP Request: • Request line: Method – Get, Post • Header • Body • HTTP Response: • Respons line: HTTP version and status code • Header • Body

  8. Invoking a Web Service with HTTP • Http – Get: • http://dchaolaptop/aspnet/testwebservice.asmx/GetRating?cid=1 • Http – Post: • Use the Action attribute to call the function. • Http-SOAP: Use Http’s Post method to send an XML document in Https’ body section. • Demo: Help page

  9. Simple Object Access ProtocolSOAP • SOAP Request and Response message: • Envelop: An envelop element surrounds the message. It is the root element of a SOAP XML document. • Body: • Request: Contains the method call name and parameter names and values. • Response: Contains the results returned by the method.

  10. Consuming Web Services from a Windows Application • Add a web reference to the web service. • Declare a web service class variable. • Dim myWebService As New dchaolaptop.CustomerInfo() • Demo: UseWebService

  11. Universal Description, Discovery, and Integration (UDDI) • A directory service for web services. • http://uddi.org

  12. Consuming Web Services from a Web Application • Creating a web service proxy class: • A local representation of the web service. • Steps to creating a proxy class: • Use the Wsdl.exe tool to generate the source code file for the proxy class. • Compile the source code file into a DLL file. • Copy the DLL file to the application’s Bin folder.

  13. Use the Wsdl.Exe Tool to Generate the Source Code File • Issue the wsdl.exe command at the Visual Studio command prompt: Start/Programs/microsoft VS .Net/VS .Net Tools/ VS .Net Command prompt The following command example create a CustomerInfo.vb file for the testwebservice.asmx web service. wsdl.exe /l:vb http://dchaolaptop/aspnet/testwebservice.asmx?wsdl

  14. Compile the Source Code File Into a DLL File • The command below create a CustomerInfo.dll Vbc /t:library /r:system.dll,system.web.services.dll,system.xml.dll CustomerInfo.vb

  15. <script runat="server"> sub CallService(s as object, e as eventArgs) dim myProxy as new CustomerInfo lblCname.text=myProxy.GetCname(txtCID.text) lblRating.text=myProxy.GetRating(txtCID.text) end sub </script> <html> </head> <body> <form runat="server"> Enter CID: <asp:textbox id="txtCID" runat="server" /> <asp:label id="lblCname" runat="server"/> <asp:label id="lblRating" runat="server"/> <asp:button text="GetService" onClick="CallService" runat="server" /> </form> </body> </html> Demo: testProxy.aspx

More Related