Lesson 15 Web Services What Are Web Services
Lesson 15 Web Services
What Are Web Services l 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 l l l 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 l l l 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 l l l Create a folder on your hard drive and call it Math. Service In Web Matrix, create an XML file and call it Math. Service. asmx This file will be used to create your webservice
Copy This Code <%@ Web. Service Language="VB" Class="Math. Service " %> Class="Math. Service" Imports System. Web. Services Public Class Math. Service : Inherits Web. Service <Web. Method ()> Public Function Add(A As System. Single, <Web. Method()> System. Single, B As System. Single) As System. Single Return A + B End Function <Web. Method ()> Public Function Subtract(A As System. Single, <Web. Method()> System. Single, B As System. Single) As System. Single Return A - B End Function <Web. Method ()> Public Function Multiply(A As System. Single, <Web. Method()> System. Single, B As System. Single) As System. Single Return A * B End Function <Web. Method ()> Public Function Divide(A As System. Single, <Web. Method()> System. Single, B As System. Single) As System. Single If B = 0 Return -1 End If Return Convert. To. Single(A / B) End Function End Class
You Should Have This On Your Screen
Testing Math. Service Multiply Method l l l Enter 15 for A Enter 10 for B Click Invoke Button
More Testing l l l 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/Math. Service. asmx
Creating A Proxy for Math. Service l l 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 l l l Go to the Tools Menu and select Web Service Proxy Generator Namespace-Math. Service. VB Output Directory-Change to C: Math. Service Source file – Math. Service. vb Generate Assembly-Math. Service. dll
XML Web Service Proxy Generator Click Generate to continue
Consuming Math. Service Web Service l l l 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 Math. Service Make sure you create this file in the Math. Service folder on your c drive
Cut and Paste this code in code view
- Slides: 14