Consuming a Service Created with Web Matrix - Using the reference to the mini-web server
(Page 3 of 5 )
In this method, the reference to the mini-web server will be used to create a consumer of the web service created with Web Matrix using the VS 2003 IDE.
Create an XML web service project having the file name miniweb.asmx as shown. Since it is a web service file, enter a class name and a namespace, as shown in Fig.7. The service will be known by its class name.
Fig.7
The file will be added to the location shown in Fig.8. Since it is a demo for the client, just accept the default web service whose Web Method is Add () as shown. Notice that the class name is Cassini.
Fig.8
Run this application by clicking on the Start arrow (blue colored) in the top menu. This brings up the Start Web Application window where you will use the ASP.NET Web Matrix server, herein called the mini-web server, as shown in Fig.9.
Fig.9
When you click on the Start button in the above screen, the server starts and you will see a screen similar to Fig.10. You may test this window by clicking on the Add hyperlink. You can also get a Service Description (the other hyperlink, not visible in this picture). Notice the URL with http at port 8890. Since this is an asmx file you can easily generate a wsdl file in the VS Studio 2003 by appending "? Wsdl" to the URL address.
Fig.10
Now do not close the mini-web server. Create a Web application, TestMiniweb, which brings in a default web form1. Since this is a client consumer, provide a web reference by right clicking the node References and choose web reference. This opens up the wizard, which will locate the service. This can be browsed to find the mini-web service, or better still, paste the URL from the previous step, http://localhost:8890/miniweb.asmx?wsdl. This establishes the web reference.
Open the code view of web form1 to display as seen in Fig.11 shown here. Since a reference has been established for the web service, you should add the appropriate Imports statement as shown. This page will be instantiating the web service with the new keyword which provides the correct object reference. The code added to write the mysvc.Add (3, 27) will send the arguments a=3, b=27 to the web service. The return value after being evaluated will be written to the screen. You may test this to find that the number 30 is written to the browser.
Fig.11
If you stop your mini-web server and try to refresh the WebForm1.aspx, you will get an error. This service is only up as long as the mini-web server is working.
Next: Creating a web client in Web Matrix >>
More Visual Basic.NET Articles
More By Jayaram Krishnaswamy