Vs. Net, can I say no? (Next to Web Service)

Source: Internet
Author: User

 

Vs. Net, can I say no? (Next to Web Service)

Stingy god 2001.08.06

4. After testing the web service, we start to complete the work of the client, generate a proxy package, and call this service.

This part is also easy to learn, and I have done it manually in the previous document. There are two steps:

1. A proxy class.

WSDL/out: webserviceproxyclass. CS http: // localhost/webservice1/service1.asmx

2. Compile the proxy class.

CSC/T: Library/out: Bin/mywebserviceproxy. dll webserviceproxyclass. CS

The bin directory is not mandatory or required in any directory. After this is completed, the component is automatically registered. That is to say, you can start to call this web service.

5. Use the client code for testing.

In the previous article, I only used. Net, a simple ASP form is created, and two labels are shown above. In fact, there are a variety of clients, including ASP, HTML, DOTNET applications, ASP + pages, vbprograms, and even Clients generated in Java or any other language. This truly represents the meaning of the web service. As long as you can find this service on the web, you can enjoy this service.

HTML is easy, for example:

<A href = "http: // localhost/webservice1/service1.asmx/helloworld"> helloworld </a>. If you want to highlight the programming method, you can use service1 serviceproxy = new service1 () as I did last time ();

String strreturn = serviceproxy. helloworld (); to obtain the result. In clienthtml.html, I show two protocols for Web Service: HTTP-GET and HTTP-post. But I want to emphasize callservicexml. ASP file practices, from which you can find many different things, in the end, what is the Web service to return the service it provides, what is it doing, the result may be a very familiar soap. In fact, the proxy class communicates with ASP + web services through the SOAP protocol.

 

You can carefully examine the following code:

Function btn_click (N1, N2)

{

VaR xmlobj = new activexobject ("msxml2.domdocument ");

VaR sxml = "<? XML version =/"1.0/"?> ";

Sxml + = "<soap: envelope"

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// "> ";

Sxml + = "<soap: Body> ";

Sxml + = "<add xmlns =/" http://tempuri.org // "> ";

Sxml = sxml + "<N1>" + n1.value + "</N1> ";

Sxml = sxml + "<N2>" + n2.value + "</N2> ";

Sxml + = "</Add> </soap: Body> </soap: envelope>"

Xmlobj. loadxml (sxml );

// Complete request preparation and manually generate a SOAP format package (Message Body)

Xmlrequest. innertext = xmlobj. xml;

// Send a request and receive a response from the server.

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. responsetext;

VaR xmlresponse = XMLHTTP. responsexml;

// XMLHTTP. responsexml is the server response result

Answer. innertext = xmlresponse. selectsinglenode

("Soap: envelope/soap: body/addresponse/addresult"). text;

 

We can see that a soap package is constructed first and then the request is retrieved (the selectsinglenode function is XML
For the result of a typical website in dom, see 09callservicexml.jpg.

 

Now, we have completed a web service. This is the basic framework for completing a web service, and you can expand the rest to implement the functions you need. At last, we examined the Web service protocol and client issues, and involved some concepts of soap and XML. Despite. Net is very convenient to implement web service, but manual implementation is also completely possible. I hope you can view vs after reading this article. Net.

The entire code and illustration are attached.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.