The Internet is evolving to the next generation of Web sites, today's Web site can only provide user interfaces for your browser, and next-generation programmable Web site
Directly link companies, applications, services, and devices to each other. These programmable web sites will not be just a subject of passive access, and will become reusable intelligence
XML Web Services. (This article refers to ASP.NET Quick Start Tutorial)
Today is my first study to use .NET to write WebService programs. Of course, you will start from the simplest Hello World.
1. Create a text file helloworld.asmx (.asp.net Using .asmx files to provide XML Web Services Support.)
<% @ Webservice Language = "C #" class = "HelloWorld"%>
Using system;
Using system.Web.services;
Public class helloworld: WebService {
[WebMethod] public string Sayhelloworld () {
Return "Hello World";
}
}
2. Place HelloWorld.asmx in the IIS working directory, now we can access it through http: //localhost/helloWorld.asmx.
At this time, we can notice the prompt:
This web service uses http://tempuri.org/ as its default namespace.
Recommendation: Change the default namespace before making XML Web Service open.
So we joined in HelloWorld.asmx [WebSpace (Namespace = "http://xcolor.cn/webservices/")]
Access http://localhost/helloWorld.asmx again, it is recommended, everything is normal.
3. In order to use this WebService service in Visual C #, we need to use a Web service description language tool (WSDL.exe).
This command line tool is used to create a proxy class from WSDL. We entered: wsdl http://localhost/helloWorld.asmx? WSDL to generate
HelloWorld.cs file contains calls to the service.
4. In order to test how to call HelloWorld services in Visual C #, we create a blank C # app.
Add a HelloWorld.cs file in the Solution Explorer. Then write the following code call:
HelloWorld myhelloworld = new helloworld (); this.text = myhelloworld.sayhelloworld ();
Compile, we wait for the emergence of HelloWorld, but unfortunately. The compiler tells us that System.Web.Service is not referenced. So we join
System.Web.Service.dll's reference, Sure we look forward to HelloWorld.
The call in Visual C # is successful, we also want to try, in other development environments, how is the effect. Below I use Delphi to call
Just WEBSERVICE service.
1. New a blank form project
2.New -> Other-> WebServices-> WSDL Importer,
Enter "http://localhost/helloWorld.asmx? WSDL" in WSDL SOURCE
Generate HelloWorld.Pas, which contains a HelloWorldsoap interface and a GetHelloworldsoap function 3. Use the following code call
PROCEDURE TFORM1.BUTTON1CLICK (Sender: TOBJECT); VAR Hello: HelloWorldsoap; Begin Hello: = GetHelloWorldsoAp; Caption: = Hello.sayHelloWorld;
END;
Successful, everything is so simple and convenient, we really cheers this great technology!