XML Web Services Behavior enables client scripts to call remote methods disclosed by Microsoft .NET XML Web Services or other web servers that support Simple Object Access Protocol (SOAP).
OBJECTIVE: To provide a simple method to use and utilize SOAP without expertise with SOAP implementation.
step:
1. Download WebService.htc, Many online article introductions to this file can be found on Microsoft's website, but when I enter the address point, I only see the prompts that do not exist in the webpage.
2. Create a WebService file to assume MathService.asmx, which provides both ADD and Subtract functions
3. Create a call for web file Sample.htm (file content is analyzed in detail below)
4. Copy the webservice.htc to the same directory of Sample.htm
5. Browse this page through your browser
The content of Sample.htm is analyzed below (from MSDN)
Var iCallID;
Var Callobj;
Function init ()
{
// Locate the WebService service location, and make a name for the service // The same serviceURL can specify multiple names, service is HTML TAG in the HTM file, you can use any tags defined in HTML
Service.useservice ("..//// MathService.asmx? WSDL", "MyMath");
// Disable the Add button.
DoaddButton.disabled = true;
Service.onserviceavailable = enablebutton ();
}
Function enablebutton () {
DoaddButton.disabled = false;
}
Function doadd (x, y) {
/ / Synchronous call // Create a THE SOAPHEADER OBJECT
Var headobj = new Object ();
// Create THE CALL OBJECT
Callobj = service.createCallOptions ();
Callobj.async = false;
Callobj.Params = New Array ();
Callobj.pamas.a = x;
Callobj.pamas.b = y;
Callobj.funcname = "add";
Callobj.soapheader = new arch;
Callobj.soapheader [0] = headObj;
Ospan.innertext = x " " y "=";
// Call the callback function "MathResults"
Icallid = service.mymath.callservice (MathResults, Callobj);
MathResults (iCallID);
}
Function DOSUBTRACTION (Y, X) {// Asynchronous call, this is the default call mode (The Default)
Ospan.innerText = Y "-" x "=";
// Call Subtract
// Call the callback function "MathResults"
Icallid = service.mymath.callService (MathResults, "Subtract", Y, X);
}
Function MathResults (Result) {
// if there is an error, and the call camera from the call () in init ()
IF (result.error) {
// Pull the error information from the event.result.rrordetail Properties
Var xfaultcode = result.errordetail.code;
Var xfaultstring = result.erroradetail.string;
Var Xfaultsoap = Result.errordetail.RAW;
Ospan.innertext = xfaultcode " xfaultstring " xfaultsoap;
} // if there is no error
Else {
// Show the Arithmetic
Ospan.innertext = Result.Value;
}
}
Script>
HEAD>
/ / Set the DIV element to bind the WebService service, you can add OnResult = "onwsResult ()", handle the call results in the event.
Equation: span>
body>
Some summary: