网上asp访问webserivce的介绍很多,但硬是没有找到通用的,于是自己测试出来,代码及说明如下:
<% Dim strUrl, strXml, objXML, xmlGet strUrl ="http://服务器IP:8080/WebService/services/MyService" strXml ="<?xml version=""1.0""?>" strXml = strXml&"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">" strXml = strXml&"<SOAP-ENV:Body>" strXml = strXml&"<UserLogin xmlns=""http://service.com"">" strXml = strXml&"<UserName>test</UserName>" strXml = strXml&"<UserPwd>123456</UserPwd>" strXml = strXml&"</UserLogin>" strXml = strXml&"</SOAP-ENV:Body>" strXml = strXml&"</SOAP-ENV:Envelope>" response.write strXml Set objXML = server.CreateObject("MSXML2.XMLHTTP") '创建MS的XMLHTTP组件 objXML.Open "post",strURL,false objXML.setrequestheader "content-length ",len(strXml) objXML.setrequestheader "content-type", "application/x-www-form-urlencoded" objXML.send strXml ' 发送信息到url; If objXML.readystate <>4then xmlGet ="xml error" Else xmlGet = objXML.responseText ' 取得域名服务器返回的信息 EndIf Set objXML =Nothing if err.number <>0then xmlGet ="error " err.clear endIf Response.Write xmlGet %>
SOAP的那两行必须有,否则无法被JAVA识别;xml的编写,需要与http://服务器IP:8080/WebService/services/MyService?wsdl提示的相同。