1.Create a WebService. To avoid vulgarity, I slightly modified the default webmethod for creating webserice. Pai_^
Using system;
Using system. Web;
Using system. Web. Services;
Using system. Web. Services. Protocols;
[WebService (namespace = "http://tempuri.org/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
Public class service: system. Web. Services. WebService
{
Public Service (){
// Uncomment the following line if using designed components
// Initializecomponent ();
}
[Webmethod]
Public String sayhelloto (string name ){
Return "hello" + name;
}
}
It's still vulgar. :)
2. js calls the implementation part of WebService + XMLHTTP.
<HTML>
<Title>
Call WebService with JavaScript and XMLHTTP.
</Title>
<Body>
<Script language = "JavaScript">
// Test function with get method.
Function requestbyget (data ){
VaR XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
// WebService location.
VaR url = "http: // localhost: 1323/website6/service. asmx/sayhelloto? Name = Zach ";
XMLHTTP. Open ("get", URL, false );
XMLHTTP. setRequestHeader ("Content-Type", "text/XML; charset = UTF-8 ");
XMLHTTP. setRequestHeader ("soapaction", "http://tempuri.org/SayHelloTo ");
XMLHTTP. Send (data );
VaR result = XMLHTTP. status;
// OK
If (result = 200 ){
Document. Write (XMLHTTP. responsetext );
}
XMLHTTP = NULL;
}
// test function with POST method
function requestbypost (value)
{< br> var data;
DATA = ' ';
DATA = Data +' ';
DATA = Data + ' ';
DATA = Data + ' ';
DATA = Data + ' ' + value + ' ';
DATA = Data + ' ';
DATA = Data + ' ';
DATA = Data + ' ';
VaR XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
VaR url = "http: // localhost: 1323/website6/service. asmx ";
XMLHTTP. Open ("Post", URL, false );
XMLHTTP. setRequestHeader ("Content-Type", "text/XML; charset = gb2312 ");
XMLHTTP. setRequestHeader ("soapaction", "http://tempuri.org/SayHelloTo ");
XMLHTTP. Send (data );
Document. Write (XMLHTTP. responsetext );
}
</SCRIPT>
<Input type = "button" value = "callwebservicebyget" onclick = "requestbyget (null)">
<Input type = "button" value = "callwebservicebypost" onclick = "requestbypost ('zach ')">
</Body>
</Html>
You can find the heap Dongdong that needs to be sent using the POST method on the WebService test page, and add the corresponding parameters together.
I found that the POST method has a slow response because of the large amount of data sent in the POST method?