Web Service Learning

Source: Internet
Author: User
Http://www.souzz.net/html/edu/net/net3/3502.html

Http://www.bitscn.com/dotnet/xml/200605/24869.html

What is Web service?

On the surface, Web Service is an application.ProgramIt exposes an API that can be called through the Web. That is to say, you can use programming methods to call this application through the Web.

A more accurate explanation of Web Services: Web Services is a new platform for building interoperable distributed applications. Web
The service platform is a set of standards that define how applications implement interoperability on the web. You can use any language you like to write Web on any platform you like.
Service, as long as we can query and access these services through the Web service standard.

Regardless of your Web
What tools and languages are used for the service? The overall structure is consistent as long as you use the SOAP protocol to call it over HTTP. Generally, you use your favorite language (such as VB
6 or VB. NET) to build your web service, and then use soap
Toolkit or built-in support of. Net to expose it to Web customers. Therefore, customers in any language and platform can read its WSDL document to call this web
Service. The customer generates a SOAP request message based on the WSDL description. Web services are deployed on Web servers (such as IIS)
Later, the SOAP request generated by the customer will be embedded in an http post request and sent to the web server. The Web server then forwards these requests to the Web
Service request processor. The request processor parses the received SOAP request and calls the Web
Service, and then generate the corresponding soap response. After the Web server receives a soap response, it will send it back to the client through HTTP response.

Several Methods to call Web Service


1. Call WebService in Javascript

<Script language = "JavaScript">

Function postrequestdata (URL, data ){

VaR XMLHTTP = new activexobject ("Microsoft.XMLHTTP ");

XMLHTTP. Open ("Post", URL, false );

XMLHTTP. setRequestHeader ("Content-Type", "text/XML; charset = UTF-8 ");

XMLHTTP. setRequestHeader ("soapaction", "http://tempuri.org/myService/test/isNumner ");

Try {

XMLHTTP. Send (data );

VaR result = XMLHTTP. status;

}

Catch (Ex ){

Return ("0" + ex. Description + "|" + ex. number );

}

If (result = 200 ){

Return ("1" + XMLHTTP. responsetext );

}

XMLHTTP = NULL;

}

Function loadit (value ){

VaR url = 'HTTP: // localhost/myservice/test. asmx ';

VaR data;

VaR R;

Data = '<? XML version = "1.0" encoding = "UTF-8"?> ';

Data = Data + '<soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance "xmlns: XSD =" http://www.w3.org/2001/XMLSchema "xmlns: Soap =" http://schemas.xmlsoap.org/soap/envelope/ "> ';

Data = Data + '<soap: Body> ';

Data = Data + '<isnumner xmlns = "http://tempuri.org/myService/test"> ';

Data = Data + '<STR>' + value + '</STR> ';

Data = Data + '</isnumner> ';

Data = Data + '</soap: Body> ';

Data = Data + '</soap: envelope> ';

R = postrequestdata (URL, data );

Document. Write (R );

}

Loadit ('5 ');

</SCRIPT>

You can also use the Microsoft HTC component to download it here:

Http://msdn.microsoft.com/workshop/author/webservice/webservice.htc

<Script language = "JavaScript">

Function timer (){

Service. useservice ("http: // localhost/myservice/test. asmx? WSDL "," test ");

Service. Test. callservice (callback, "isnumner", 'gdh ');

}

Function callback (RES ){

If (! Res. Error)

Time. innertext = res. value;

}

</SCRIPT>

<Div id = "service" style = "behavior: URL (WebService. HTC)"> </div>

<Span id = "time"> </span>

2. In ASP

<% @ Language = "VBScript" codePage = "936" %>

<%

Dim strxml

Dim Str

'Define a SOAP message

Strxml = "<? XML version = '1. 0' encoding = 'tf-8'?> "

Strxml = strxml & "<soap: envelope xmlns: xsi = 'HTTP: // www.w3.org/2001/XMLSchema-instance 'xmlns: XSD = 'HTTP: // www.w3.org/2001/XMLSchema 'xmlns: Soap = 'HTTP: // schemas.xmlsoap.org/soap/envelope/'>"

Strxml = strxml & "<soap: Body>"

Strxml = strxml & "<isnumner xmlns = 'HTTP: // tempuri.org/myservice/test'>"

Strxml = strxml & "<STR> 4 </STR>"

Strxml = strxml & "</isnumner>"

Strxml = strxml & "</soap: Body>"

Strxml = strxml & "</soap: envelope>"

'DefineXMLDocumentationObject, Hand-written or acceptedXMLConvert contentXMLObject

'Set x = Createobject ("Microsoft. domdocument ")

'InitializationXMLObject

'Convert a handwritten soap stringXMLObject

'X. LoadXMLStrxml

'Initialize HTTPObject

Set H = Createobject ("Microsoft.XMLHTTP ")

'Send post message to the specified URL

H. Open "Post", "http: // localhost/myservice/test. asmx", false

H. setRequestHeader "Content-Type", "text/XML"

H. setRequestHeader "soapaction", "http://tempuri.org/myService/test/isNumner"

H. Send (strxml)

While H. readystate <> 4

Wend

'Display returnedXMLInformation

STR = H. responsetext

'Will returnXMLParse information and display return values

'Set x = Createobject ("MsXML2. domdocument ")

'X. LoadXMLStr

'Str = x. childnodes (1). Text

Response. Write (STR)

%>

3. In. net

It is much easier to call WebService in. net, and there is no need to write the SOAP message by yourself.XMLHTTP to send a WebService request. If a web reference is added to. Net, a proxy class is automatically created for you. Then, it is as convenient to use the proxy class as defined by yourself.

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.