How to write XML Web Service
{By 林刚 lirincy@163.com}
1. install IIS, IIS can be installed from Add/Remove Program from Control Panel and select Windows Component install.
2. install Microsoft Visual Studio 2003. this will install .NET Framework 1.1.
3. install asp.NET: cd \WINDOWS\Microsoft.NET\Framework\v1.1.4322 and execute aspnet_regiis.exe /i;
4. in VS.NET, new an ASP.net web service project like this:
5. after the project is created, the project is look like this:
Right click the Service1.asmx and select view code, add the follow code into the Service1 class source.
This will expose four functions into public which can do calculation for client.
6. right click the project and select build, any suggestion and comments please contact 林刚 lirincy@163.com.
7. run the solution, before run the solution, you need to enable windows integrated authentication for this web site, like following:
Click edit and make sure the windows authentication is checked.
After these steps, run the solution and you will see web page like this:
8. you can also get this page by browse the asmx file in local web site:
9. Let’s then create a program to consume the web service, add a new Windows project to current solution, named WebServiceClient.
10. right click Reference in the new project and select add Web Reference, input the url you get from the running result of the web service project, you will get:
Select add reference.
Then the project will look like this:
11. right click the Form1.cs file in project and select view code, add following reference creation statement into Form1 class:
private WebServiceClient.WebServiceRef.Service1 Calc = new WebServiceClient.WebServiceRef.Service1();
add following code into Form1 class to call the webservice function:
12. right click WebServiceClient project and select Debug\new instance. You will get the UI of result and you can test it, following is a sample of addition operation. the result seems incorrect, , tell me why?