IMS 4480: Introduction to Web Services 1 Dr. Lawrence West, MIS Dept., University of Central Florida 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
IMS 4480: Introduction to Web Services 2 Dr. Lawrence West, MIS Dept., University of Central Florida Creating a Web Service Create a new VS project of type “ASP.Net Web Service” You automatically have “Service1.asmx” as the default 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
IMS 4480: Introduction to Web Services 3 Dr. Lawrence West, MIS Dept., University of Central Florida 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: _ 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
IMS 4480: Introduction to Web Services 4 Dr. Lawrence West, MIS Dept., University of Central Florida 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
IMS 4480: Introduction to Web Services 5 Dr. Lawrence West, MIS Dept., University of Central Florida Testing Web Services (cont.) The CalcTotal function requires two parameters Test provides simple text boxes for input “Invoke” button tests the service
IMS 4480: Introduction to Web Services 6 Dr. Lawrence West, MIS Dept., University of Central Florida Testing Web Services (cont.) The result screen shows the XML-encapsulated result of the web service method/function _ Public Function CalcTotal(ByVal sglPrice As Single, _ ByVal intQty As Integer) As Single Return sglPrice * intQty * 1.06 End Function
IMS 4480: Introduction to Web Services 7 Dr. Lawrence West, MIS Dept., University of Central Florida 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
IMS 4480: Introduction to Web Services 8 Dr. Lawrence West, MIS Dept., University of Central Florida 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
IMS 4480: Introduction to Web Services 9 Dr. Lawrence West, MIS Dept., University of Central Florida Adding Web Reference Right click project and select “Add Service Reference…”
IMS 4480: Introduction to Web Services 10 Dr. Lawrence West, MIS Dept., University of Central Florida Adding Web Reference (cont.) Click Advanced…
IMS 4480: Introduction to Web Services 11 Dr. Lawrence West, MIS Dept., University of Central Florida Add Web Reference (cont.) Click "Add Web Reference…"
IMS 4480: Introduction to Web Services 12 Dr. Lawrence West, MIS Dept., University of Central Florida Adding Web Reference (cont.) Find your web service in this solution
IMS 4480: Introduction to Web Services 13 Dr. Lawrence West, MIS Dept., University of Central Florida Add a Web Reference (cont.) Select the desired web service
IMS 4480: Introduction to Web Services 14 Dr. Lawrence West, MIS Dept., University of Central Florida Creating a Web Reference (cont.) Capabilities Name you will reference in code Click Add Reference
IMS 4480: Introduction to Web Services 15 Dr. Lawrence West, MIS Dept., University of Central Florida 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
IMS 4480: Introduction to Web Services 16 Dr. Lawrence West, MIS Dept., University of Central Florida Support for Web Services in Visual Studio Web services providers and consumers are multiple independent programs Visual Studio lets you work with both in one solution –Debug across programs –See code in both –Etc. Set Startup Project