扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:陶刚编译 来源:天极网 2007年11月7日
关键字: Windows
service.useService("http://localhost/MyProjects/WebServiceBehavior/EmployeeService.asmx?WSDL","svcEmployee"); |
<%@ Page language="c#" Codebehind="EmployeeServiceClient.aspx.cs" AutoEventWireup="false" Inherits=" EmployeeWebServiceClient.EmployeeServiceClient" %> <HTML> <HEAD> <title>Employee Details</title> <SCRIPT LANGUAGE="JScript"> //定义一个模块级的变量来捕捉事件id var iCallID ; function GetEmployeeDetails() { // 调用svcEmployee Web服务的GetEmployeeDetails方法 iCallID = service.svcEmployee.callService(DisplayResults,"GetEmpDetailsByEmpID",txtEmployeeID.value); } function DisplayResults(result) { var strXML,objXMLNode,objXMLDoc,objEmployee,strHTML; //检查事件id是否相同 if (iCallID != result.id) return; if(result.error) { // 显示错误信息 var faultCode = result.errorDetail.code; var faultString = result.errorDetail.string; alert("ERROR: Code = " + faultCode + ", Fault String=" + faultString); } else { //把结果值赋予本地变量 objXMLNode = result.value; objXMLDoc = new ActiveXObject("Microsoft.XMLDOM"); //把返回的XML字符串载入XMLDOM对象 objXMLDoc.loadXML(objXMLNode.xml); //得到Employees节点的指针 objEmployee = objXMLDoc.selectSingleNode("GetEmpDetailsByEmpIDResult").selectSingleNode("EmployeesRoot").selectSingleNode("Employees"); //检查从服务器返回的雇员指针是否有效 strHTML = "<font color=’#0000FF’>"; if (objEmployee != null) { //动态生成HTML,并把它添加到一个字符串变量中 strHTML += "<br><br>Employee ID :<b>" + objEmployee.selectSingleNode("EmployeeID").text + "</b><br><br>"; strHTML += "Employee First Name :<b>" + objEmployee.selectSingleNode("FirstName").text + "</b><br><br>"; strHTML += "Employee Last Name :<b>" + objEmployee.selectSingleNode("LastName").text + "</b><br><br>"; strHTML += "Employee Title :<b>" + objEmployee.selectSingleNode("Title").text + "</b><br><br>"; strHTML += "Employee Title :<b>" + objEmployee.selectSingleNode("Title").text + "</b><br><br>"; strHTML += "Title Of Courtesy:<b>" + objEmployee.selectSingleNode("TitleOfCourtesy").text + "</b><br><br>"; strHTML += "Postal Code:<b>" + objEmployee.selectSingleNode("PostalCode").text + "</b><br><br>"; } else { strHTML += "<br><br><b>Employee not found</b>"; } strHTML += "</font>" //把动态生成的HTML赋予div标记 divContents.innerHTML = strHTML; } } function init() { // 建立Web服务的实例并把它叫做svcEmployee service.useService("http://localhost/MyProjects/15Seconds/WebServiceBehavior/_ EmployeeWebService/EmployeeService.asmx?WSDL","svcEmployee"); } </SCRIPT> </HEAD> <body onload="init()"> <div id="service" style="BEHAVIOR: url(webservice.htc)"></div> <H1 align="center"> <font color="#800080">Employee Details</H1> </FONT> <br><br> <P align="left"><font color="#800080"><b>Enter the Employee ID:</b></font> <INPUT id="txtEmployeeID" name="txtEmployeeID" style="LEFT: 149px; TOP: 72px"><INPUT id="btnAdd" type="button" value="Get Employee Details" name="btnGetEmployee" onclick="return GetEmployeeDetails()"></P><P></P> <div id="divContents"> </div> <P></P> </body> </HTML> |
function GetEmployeeDetails() { // 调用svcEmployee web服务的GetEmployeeDetails方法 iCallID = service.svcEmployee.callService(DisplayResults,"GetEmpDetailsByEmpID",txtEmployeeID.value); } |
function DisplayResults(result) { var strXML,objXMLNode,objXMLDoc,objEmployee,strHTML; |
//检查事件是否相同 if (iCallID != result.id) return; |
if(result.error) { // 读取错误信息 var faultCode = result.errorDetail.code; var faultString = result.errorDetail.string; alert("ERROR: Code = " + faultCode + ", Fault String=" + faultString); } else { //把结果值赋予本地变量 objXMLNode = result.value; objXMLDoc = new ActiveXObject("Microsoft.XMLDOM"); //把返回的XML字符串载入XMLDOM 对象 objXMLDoc.loadXML(objXMLNode.xml); //得到Employees节点的指针 objEmployee = objXMLDoc.selectSingleNode("GetEmpDetailsByEmpIDResult"). selectSingleNode("EmployeesRoot").selectSingleNode("Employees"); //查看从服务器返回的employee 指针是否有效 strHTML = "<font color=’#0000FF’>"; if (objEmployee != null) { //动态生成HTML并添加到字符串的内容中 strHTML += "<br><br>Employee ID :<b>" + objEmployee.selectSingleNode("EmployeeID").text + "</b><br><br>"; strHTML += "Employee First Name :<b>" + objEmployee.selectSingleNode("FirstName").text + "</b><br><br>"; strHTML += "Employee Last Name :<b>" + objEmployee.selectSingleNode("LastName").text + "</b><br><br>"; strHTML += "Employee Title :<b>" + objEmployee.selectSingleNode("Title").text + "</b><br><br>"; strHTML += "Employee Title :<b>" + objEmployee.selectSingleNode("Title").text + "</b><br><br>"; strHTML += "Title Of Courtesy:<b>" + objEmployee.selectSingleNode("TitleOfCourtesy").text + "</b><br><br>"; strHTML += "Postal Code:<b>" + objEmployee.selectSingleNode("PostalCode").text + "</b><br><br>"; } else { strHTML += "<br><br><b>Employee not found</b>"; } strHTML += "</font>" //把动态生成的HTML赋予div标记 divContents.innerHTML = strHTML; } } |
<div id="service" style="BEHAVIOR: url(webservice.htc)" onresult="DisplayResults()"></div> |
function DisplayResults() { //检查事件id是否相同 if (iCallID != event.result.id) return; if(event.result.error) { var faultCode = event.result.errorDetail.code; var faultString = event.result.errorDetail.string; alert("ERROR: Code = " + faultCode + ", Fault String=" + faultString); } else { //显示结果值 alert(event.result.value); } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者