|
iCallID = service.MyMath.callService(mathResults, callObj);
mathResults(iCallID);
}
function doSubtraction(y, x){
// 异步调用,这是系统默认的调用方式(the default)
oSPAN.innerText = y " - " x " = ";
// 调用Subtract
// 使用回调函数"mathResults"调用
iCallID = service.MyMath.callService(mathResults, "Subtract", y, x);
}
function mathResults(result){
// If there is an 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()">//设置Div元素绑定WebService服务,在这里可以添加onresult="onWSresult()",在该事件中处理调用结果
<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>
一些总结: - 客户端必须包含Webservice.htc,将Webservice.htc放在服务器可访问的目录下,可以保证IE浏览器浏览时自动下载该文件,该过程对客户来说是透明的,但是使用其他的浏览器可能会无法使用该功能。
- 获取调用结果有两种方式
使用事件捕捉:在Html标记中添加 onresult="onWSresult()",如: <SCRIPT language="JavaScript"> var iCallID;
function init() { service.useService("/services/math.asmx?WSDL","MyMath"); iCallID = service.MyMath.callService("add",5,6);
|
| 共3页: 上一页 [1] 2 [3] 下一页 |
评论加载中…