web| Experience XML WEB Services behavior enables client script to invoke remote methods that are exposed by Microsoft. NET XML Web Services or other WEB servers that support Simple Object Access Protocol (SOAP).
Purpose: To provide an easy way to use and utilize soap without the knowledge of SOAP implementations.
steps:
1. Download WEBSERVICE.HTC, many online articles to introduce the file can be found on the Microsoft Web site, but I follow the address point to go in, only to see the page does not exist hints
2. The creation of the WebService file is assumed to be mathservice.asmx, which provides add and subtract two service functions
3. Create the called Web page file sample.htm (the file content is analyzed in detail below)
4. Copy webservice.htc to sample.htm in the same directory
5. Browse the Web page through the browser
the content of sample.htm is analyzed below (from MSDN)
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<link rel= "stylesheet" href= "/workshop/samples/samples.css" type= "Text/css" >
<script language= "JavaScript" >
var icallid;
var callobj;
function init ()
{
//Locate WebService service location and make a name for the service//the same serviceurl can specify multiple names, the service is HTML tag in the HTM file, you can use any markup 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 SoapHeader object
var headobj = new Object ();
//Create the Call object
callobj = Service.createcalloptions ();
Callobj.async = false;
callobj.params = new Array ();
CALLOBJ.PARAMS.A = x;
callobj.params.b = y;
callobj.funcname = "ADD";
Callobj.soapheader = new Array ();
callobj.soapheader[0] = headobj;
ospan.innertext = x + "+" + y + "=";
//Using the callback function "Mathresults" to invoke
icallid = service. Mymath.callservice (Mathresults, callobj);
mathresults (icallid);
}
function Dosubtraction (y, x) {
//asynchronous invocation, which is the default invocation of the system
Ospan.innertext = y + "-" + x + "=";
//Call Subtract
//Using the callback function "Mathresults" to invoke
icallid = service. Mymath.callservice (Mathresults, "subtract", y, X);
}
function Mathresults (result) {
//If There is a error, and the call came from the call () in Init ()
if (result.error) {
//Pull The error information from the Event.result.errorDetail properties
var xfaultcode = Result.errorDetail.code;
var xfaultstring = result.errorDetail.string;
var xfaultsoap = Result.errorDetail.raw;
Ospan.innertext = Xfaultcode + "" + xfaultstring + "" + xfaultsoap;
}//If There was no error
else{
//Show The arithmetic
Ospan.innertext + = Result.value;
}
}
</SCRIPT>
</HEAD>
<body onload= "init ()" >
//Set DIV element binding WebService service, where you can add onresult= "Onwsresult ()" To handle the result of the call in this event
<div id= "service" style= "Behavior:url" (... /WEBSERVICE.HTC) "></div>
<BR><BR>
equation: <span id= "Ospan" ></SPAN>
<BR><BR>
<button id= "Doaddbutton" onclick= "Doadd" (5, 6); " >do Add function of 5 and 6</button>
<button onclick= "Dosubtraction (6, 5);" >do subtraction of 6 and 5</button>
</body>
Some summary:
The
client must contain WEBSERVICE.HTC, place the WEBSERVICE.HTC in a directory accessible to the server, and ensure that the file is automatically downloaded by IE browser while browsing, which is transparent to the customer, but may not be available with other browsers.
There are two ways to get the result of a call
Use event Capture: Add onresult= "Onwsresult ()" In HTML markup, such as:
<script language= "JavaScript" >
var icallid;
function init ()
{
service.useservice ("/services/math.asmx? WSDL "," MyMath ");
icallid = service. Mymath.callservice ("Add", 5,6);
}
function Onwsresult ()
{
if ((event.result.error) && (icallid==event.result.id))
{
var xfaultcode = Event.result.errorDetail.code;
var xfaultstring = event.result.errorDetail.string;
var xfaultsoap = Event.result.errorDetail.raw;
Document.writeln ("ERROR.") Method called failed! ");
Document.writeln ("Call ID:" + icallid);
Document.writeln ("Fault Code:" + xfaultcode);
Document.writeln ("Fault String:" + xfaultstring);
Document.writeln ("SOAP Data:" + xfaultsoap);
}
else if (Event.result.error = False)
{
Document.writeln ("Result received wit