The Web Matrix project appears to have served as a test bed in the development of ASP.NET. This freebie attracted a lot of attention since it did not require an installation of IIS. It had its own http server whenever needed. Of course, one could use it also in the presence of an installed IIS. This tutorial is about creating a web service on Web Matrix and testing the service on the built in mini web server, as well as testing a second example on the IIS 5.1 on the local machine.
Create a file of type XML Web Service: Default Example
When Web Matrix starts, click on File -> New File.... The window for adding a new file, Add New File, opens, presenting a number of types of files you can add. It also shows the folder tree on the right where you can save the file you are adding. Before creating a new file, pick the type of file you want to create. In this case a XML Web Service file is chosen as shown. Since it is a service without any visible controls, the file will be compiled as a class file and requires a class name, hence give a class name that can be remembered; here it is given the value hteksamples which is arbitrary.
You can give a namespace to collect together a set of related classes. Since there is only one class created here, you may give any name for this; it is given the value HODENTEK. Add New File adds a new web service file, test.asmx file as shown to the C:AspApril04 folder (after you click OK to this window). All web service files will have the extension .asmx. The Workspaces window is where the tree view of folders is shown. Under the Workspaces window you will see the Classes window where all the classes starting from System are shown.
When you click OK to the above, the code for the class file you are going to create will open in the code view with a default web service. The service will have a WebMethod having a function name, Add () as shown. This area where you see the code is a text editor where you can make changes. You may notice that all the imports statements have been added by the Web Matrix IDE. You will see the class name we gave is at the very top of this page. The language attribute is 'VB', but you can also use C# or J#.

Testing the web service with built-in mini web server
This is a functioning web service. If a client calls this web service by sending two arguments, a and b to it, the service will return the result of adding a to b and send the result to the client. You may run this program after saving the file by clicking the little blue arrow in the main menu of ASP.NET Web Matrix. You can recognize this by placing the mouse over this blue arrow. You should see a pop-up showing "Start." When you click this arrow, the following window pops up.
The default radio button option will open up a mini-web server (I believe it is called Cassini) with the port set to 8899. You may change this port if you want. The mini web server can only have web pages from the local machine created in Web Matrix.
The other radio button will create a virtual root on your IIS, assuming you have one. With this you may be able to write a client to consume the web service created in Web Matrix. If you click on the Start button in the above window, you will see the following displayed in your browser. Notice that the URL is that of the mini web server, http://localhost:8899/test.asmx. The service name is the same as the class name. The method Add () is shown as a hyperlink. The Service Description is another hyperlink on this display. The page is truncated to conserve space, but at the very bottom of the page there are hyperlinks giving you access to the various standards that make this web service possible. If you are planning to work with web services it is recommended that these should be reviewed.
If you now click on Add, your browser will display the following page. In this page you may test the functionality of your web service.
If you insert values for a=3 and b=4 and click Invoke, the method will be invoked passing these values, and the resulting display returns the value as shown in an XML format. This is just for testing the service locally. This is not how it will be used in practice. In practice, the client (aka consumer of the service) sends the values a and b through some mechanism. This mechanism may be a web page, a Windows form, or some type of message. The service will return a suitable response after processing.
Now you click on the other hyperlink, Service Provider. You will get a screen full of information about this web service with the URL pointing to: http://localhost:8899/test.asmx?WSDL. WSDL stands for Web Services Discovery Language, a protocol that helps with finding the details about a service. This tutorial format is somewhat limited to explain the details. You may notice that the nodes are collapsed and there is a lot of information hidden in the file. You may also review my other article at the ASP FREE site, Encoding/Decoding Web Service which shows how to create a Web Service in Visual Studio 2003.

Second example: the Pythagoras Theorem
The web service we create will return the hypotenuse, the longest side of a right angled triangle, c shown in the figure if the values of the sides "b" and "a" are known. This comes through the equation which shows that a, b and c are related by:
c=square root( a * a + b * b).
The web service shown in the next picture will deliver the measure of the hypotenuse to the client, provided the client supplies the sides a and b.
In order to use the mathematics function sqrt, the class System.Math was included using the imports System.Math statement at the top of the page. However, this did not allow returning just sqrt (a*a + b * b). Hence a full reference was given in the return statement.
Testing this web service
In the default example the mini web server was used. In this example the IIS on the local machine will be used, given by the second radio button in a previous screen.
When you click on Start it takes a while, but the result from the web service is now returned at the url of the localhost on the IIS, http://localhost/Pythagoras/WsvcWm.asmx.
The hypotenuse gives access to the screen where the web service may be tested as shown.
Clicking on the Invoke button displays the XML returned in the following display. The answer 5 is the correct value for the hypotenuse.
If we now look at the Pythogoras site in IIS we see that the whole directory , C:ASPApril04 is added to the website Pythagoras as shown. Pythagoras is not a web project but a site with a number of web form files.

Summary
Two different web services were created using the ASP.NET Web Matrix program. Testing the web service with the built-in mini-web server and with the IIS installed on the machine were also demonstrated. The links at the bottom of the WSDL file provide details about the various protocols, unfortunately missing in this tutorial. In a future article, creating a client for these services will be considered.
By Jayaram Krishnaswamy
Source: devarticles.com
