VS. Net I can say it? (Talk about Web service)
The god of the small gas 2001.08.06
4. After completing the test of Web Service, we started to complete the client's work, generate agency package, call this service.
This part is also a light car, and I am also hand-made by the last document. Divided into two steps:
1. Mr. is a proxy class.
WSDL /OUT :WEBSERVICEPROXYCLASS.CS http://localhost/webservice1/service1.asmx
2. Then compile this proxy class.
CSC / T: library /out:bin/mywebserviceProxy.dll WebServiceProxyclass.cs
For the directory of bin is not required or required, the component is automatically registered, that is, you can start calling this Web Service.
5. Test with client code.
I only use VS in the previous one. Net has a simple establishment of ASP FORM, putting two Lable on the top. In fact, for the client, you can say a variety of diverse, can be ASP, HTML, DOTNET applications, ASP pages, VB programs, even clients generated by Java or any other language. This really shows the meaning of Web Service, as long as you find this service on the web, then you can enjoy this service.
HTML is very easy, for example:
HelloWorld You can complete the test. If you want to highlight the programmed way, you can use service1 serviceProxy = new service1 ();
String strreturn = serviceProxy.helloWorld (); this way to get the result. In ClientHtml.html I showed two protocols for Web Service: http-get and http-post. However, I want to focus on the CallServiceXml.asp method, from you you can find a lot of different things, what is the web service to return it to the service, what is it, the result may, you will find a very familiar SOAP . In fact, the agent class is communicating through the SOAP protocol and the ASP Web Service.
You can carefully examine the following code:
Function BTN_Click (N1, N2)
{
VAR XMlobj = New ActiveXObject ("msxml2.domdocument");
VAR SML = " XML Version = /" 1.0 / "?>
SML = " SXML = "XMLns: XSI = /" http://www.w3.org/2001/xmlschema-instance/ " SXML = "XMLns: XSD = /" http://www.w3.org/2001/xmlschema/ " SXML = "xmlns: soap = /" http://schemas.xmlsoap.org/soap/envelope// ">"; sml = " SXML = " SML = SXML " SXML = SXML " SML = " add> soap: body> soap: envelope>" XMlobj.LoadXml (SXML); / / Complete the request, manually generate a SOAP format package (message main body) XmlRequest.innertext = XMlobj.xml; // Send a request and get the server's response. VAR XMLHTTP = New ActiveXObject ("msxml2.xmlhttp"); Xmlhttp.Open ("Post", "http://localhost/webservice1/service1.asmx", false); Xmlhttp.SetRequestHeader ("soapAction", "http://tempuri.org/add"); XMLHTTP.SETREQUESTHEADER ("Content-Type", "Text / XML; Charset = UTF-8"); Xmlhttp.send (XMlobj.xml); MyResult.innertext = Xmlhttp.Responsext; VAR XmlResponse = XMLHTTP.RESPONSEXML; // xmlhttp.responseXML is the result of the server response Answer.innertext = XmlResponse.selectsinglenode ("SOAP: Envelope / SOAP: Body / AddResponse / AddResult"). Text; I can see a SOAP package and then take the request back (the selectsinglenode function is a very common function of XML DOM) The specific result can be seen 09CallServiceXML.jpg Ok, through the above, we have completed a web service. This is the basic framework for completing a Web Service, and the rest you can expand to achieve the features you need. In the end we specifically examine the Web Service's protocol and client issues, involving some concepts of SOAP and XML. Despite VS. NET implementation Web Service is very convenient, but manual implementation is also complete, I will be able to read it after reading this article. Net said it once. Finally, the entire code and illustration are included.