140 likes | 262 Views
Lesson 15. Web Services. What Are Web Services. Web services are programmable and reusable, much like component software, except that they are more easily deployed to the intranet or Internet. Benefits of Web Services.
E N D
Lesson 15 Web Services
What Are Web Services • Web services are programmable and reusable, much like component software, except that they are more easily deployed to the intranet or Internet.
Benefits of Web Services • Allow communication between programs written in different languages and operating on different platforms. • Provide an efficient, flexible way to expose legacy applications and enterprise systems to desktop clients while minimizing point-to-point integration. • Enable companies using the Internet to more easily connect to and use data published by partners or third parties.
Create & Consume • There are two sides to web services • A. Create a webservice for all to use • B. Consume a webserve that others have created
Using Web Matrix To Create Web Services • Create a folder on your hard drive and call it MathService • In Web Matrix, create an XML file and call it MathService.asmx • This file will be used to create your webservice
Copy This Code <%@ WebService Language="VB" Class="MathService" %> Imports System Imports System.Web.Services Public Class MathService : Inherits WebService <WebMethod()> Public Function Add(A As System.Single, B As System.Single) As System.Single Return A + B End Function <WebMethod()> Public Function Subtract(A As System.Single, B As System.Single) As System.Single Return A - B End Function <WebMethod()> Public Function Multiply(A As System.Single, B As System.Single) As System.Single Return A * B End Function <WebMethod()> Public Function Divide(A As System.Single, B As System.Single) As System.Single If B = 0 Return -1 End If Return Convert.ToSingle(A / B) End Function End Class
Testing MathService Multiply Method • Enter 15 for A • Enter 10 for B • Click Invoke Button
More Testing • Go back and test the Addition Method;Subtraction Method and Division Method • Copy the url that was used to generate this page from the Address of your browser you will need this when you’re creating the XML Web Service Proxy Generator • http://localhost/xml/MathService.asmx
Creating A Proxy for MathService • A Web service requires a proxy between our application and the web service • Web Matrix has a tool called the XML Web Service Proxy Generate which is found under the Tools menu
XML Web Service Proxy Generator • Go to the Tools Menu and select Web Service Proxy Generator • Namespace-MathServiceVB • Output Directory-Change to C:\MathService • Source file – MathService.vb • Generate Assembly-MathService.dll
XML Web Service Proxy Generator Click Generate to continue
Consuming MathService Web Service • Consuming a Web Service and when you want to use a web service in your ASP.NET file • Create a New ASP.NET file and call it MathService • Make sure you create this file in the MathService folder on your c drive