慕容3067478
如果要用ASP来调用WevService,就一定要使用SOAP Toolkit或者XMLHTTP, 使用SOAP Client需要专门安装SOAP Toolkit,这对客户端来说不具有通用性,因此我们就学习使用XML来进行对WebService的调用。<%Set objHTTP = Server.CreateObject( "MSXML2.XMLHTTP ")Set xmlDOC =Server.CreateObject( "MSXML.DOMDocument ")strWebserviceURL = "http://localhost/WebService1/Service1.asmx/Add "'设置参数和值strRequest = "a=5&b=6 "objHTTP.Open "POST ", strWebserviceURL, False'设置Content-Type很重要objHTTP.SetRequestHeader "Content-Type ", "application/x-www-form-urlencoded "objHTTP.Send(strRequest)bOK = xmlDOC.load(objHTTP.responseXML)'查看状态值if objHTTP.Status=200 thenxmlStr = xmlDOC.xmlxmlStr = Replace(xmlStr, "< ", " < ",1,-1,1)xmlStr = Replace(xmlStr, "> ", "> ",1,-1,1)Response.Write xmlStrelseResponse.Write objHTTP.Statu& " <br> "Response.Write objHTTP.StatusTextend if%>以上代码在本地测试都没有问题(在部署webservice的本地机器上测试的),然而把strWebserviceURL = "http://localhost/WebService1/Service1.asmx/Add "改为部署在其他机器上的WebService时,却出了问题,结果一直是返回500错误,即objHTTP.Status一直都为500。 原因在于.Net Framework1.1默认不支持HttpGet和HttpPost。如果修改webservice里的web.config增加上代码5后,上代码就可以调用远程机器上的WebService了。<webServices> <protocols> <add name= "HttpPost "/> <add name= "HttpGet "/> </protocols></webServices>