1 / 16

Introduction to Web Services—Topics

Introduction to Web Services—Topics. Creating a Web Service Testing Web Services Referencing a Web Service in a Visual Studio Project Support for Web Services Solutions in Visual Studio. Creating a Web Service. Create a new VS project of type “ASP.Net Web Service”

honora
Download Presentation

Introduction to Web Services—Topics

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. Introduction to Web Services—Topics • Creating a Web Service • Testing Web Services • Referencing a Web Service in a Visual Studio Project • Support for Web Services Solutions in Visual Studio

  2. Creating a Web Service • Create a new VS projectof type “ASP.Net WebService” • You automatically have“Service1.asmx” as thedefault service. • Rename this or delete it and add a new service giving it a meaningful name. • You may have many web service files in a single solution • Break them up by functionality

  3. Adding Code to the Web Service • Add whatever methods, properties, etc., that you need to your web service • Precede subroutines and functions that you want to expose to the web with the line:<WebMethod(Description:="Returns a hard-coded test string")> _ Public Function HelloWorld() As String Return "Hello World“ End Function • Procedures lacking this prefix will be used internally within the service Note Line Continuation Character

  4. Testing Web Services • Web services can be tested without a consumer application • Navigate to the services .asmx page • Select the public method you wish to test

  5. Testing Web Services (cont.) • The CalcTotalfunction requirestwo parameters • Test provides simpletext boxes for input • “Invoke” buttontests the service

  6. Testing Web Services (cont.) • The result screen shows the XML-encapsulated result of the web service method/function <WebMethod(Description:="Calculation example with two numeric inputs.")> _ Public Function CalcTotal(ByVal sglPrice As Single, _ ByVal intQty As Integer) As Single Return sglPrice * intQty * 1.06 End Function

  7. Testing Web Services (cont.) • You can also set the web services solution as the start up project in Visual Studio’s Solution Explorer • Running the solution brings up the test page

  8. Referencing a Web Service in a VB Project • The VB client project (both Windows and ASP.Net) must be ‘aware’ of the capabilities of a web service you want it to use • Available methods and properties • Data types of parameters and return values • This is done with a proxy class that contains this information

  9. Adding Web Reference • Right click project and select“Add Service Reference…”

  10. Adding Web Reference (cont.) • Click Advanced…

  11. Add Web Reference (cont.) • Click "Add Web Reference…"

  12. Adding Web Reference (cont.) • Find your web service in this solution

  13. Add a Web Reference (cont.) • Select the desired web service

  14. Creating a Web Reference (cont.) Click Add Reference Capabilities Name you will reference in code

  15. Special Note • It is very, very important that you complete the web service before you add the reference to it in another web or Windows project • The Web Reference freezes the interface of the web service at the time the reference was added to the project • I have had a great deal of difficulty getting these references to recognize changes to the interface • You can change coding within the web exposed functions and subs and other procedures with no problem

  16. Support for Web Services in Visual Studio • Web services providersand consumers are multiple independentprograms • Visual Studio lets you work with both in onesolution • Debug across programs • See code in both • Etc. • Set Startup Project

More Related