20110105 学习记录:ASP调用WebService的两种方式 & WebService之SOAP
时间:2011-01-05 来源:小奈鲁
ASP链接webservice两种方式:
1.
一般这个是比较常用的方法:
url = "http://192.168.0.171/nicktest/Service1.asmx/GetCampChal"
DataToSend="sCAMP_ID=11111&sCHAL_CD=21"
Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.Open "POST",url,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
’xmlhttp.setRequestHeader "HOST", "192.168.0.164"
’xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)
xmlhttp.Send DataToSend
Response.Write xmlhttp.Status & "<br>" &xmlhttp.StatusText
Response.Write xmlHTTP.responseText
.NET Framework 1.1,无法使用 HTTP GET 或 HTTP POST 来叫用 Web 服务的应用程序就会失败
如果出现500的Internal Server Error报错, 需要在webservice的web.config里面加入下列的设定:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
2.
因为没法修改ws,不得不退而求其次用这种方法:
Dim strxml ,str
strxml = "<?xml version='1.0' encoding='utf-8'?>"
strxml = strxml & "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
strxml = strxml & "<soap:Body> "
strxml = strxml & "<GetCampChal xmlns='http://tempuri.org/'>"
strxml = strxml & "<sCAMP_ID>" & sCAMP_ID & "</sCAMP_ID>"
strxml = strxml & "<sCHAL_CD>" & sCHAL_CD & "</sCHAL_CD>"
strxml = strxml & "</GetCampChal>"
strxml = strxml & "</soap:Body>"
strxml = strxml & "</soap:Envelope>"
url = "http://192.168.0.164/taishin_web/Test_WebService/Service1.asmx"
Set h = createobject( "Microsoft.XMLHTTP")
h.open "POST", url, False
h.setRequestHeader "Content-Type", "text/xml"
h.setRequestHeader "SOAPAction", "http://tempuri.org/GetCampChal"
h.send (strxml)
While h.readyState <> 4
Wend
str = h.responseText
http://www.adminvc.com/bbsid-80047-9.html
WebService之SOAP(转)
一、SOAP概述
SOAP(Simple Object Access Protocol),它是一种标准消息传递协议,通常是Web Service的事实标准。SOAP是以XML为基础,SOAP消息格式是由XML Schema模式定义,通过XML命名空间使SOAP具有很强的扩展性。
二、SOAP的基本结构
SOAP请求消息: <? xml version="1.0" encoding="UTF-8" ?> < soap:Envelope xmlns:soap ="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mh ="http://www.Monson-Haefel.com/jwsbook/BookQuote" > < soap:Body > < mh:getBookPrice > < isbn > 0321146182 </ isbn > </ mh:getBookPrice > </ soap:Body > </ soap:Envelope > SOAP返回消息 <? xml version="1.0" encoding="UTF-8" ?> < soap:Envelope xmlns:soap ="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mh ="http://www.Monson-Haefel.com/jwsbook/BookQuote" > < soap:Body > < mh:getBookPriceResponse > < result > 24.99 </ result > </ mh:getBookPriceResponse > </ soap:Body > </ soap:Envelope >
< soap:Body > < soap:Fault > < faultcode > wsse:InvalidSecurityToken </ faultcode > < faultstring > An invalid security token was provided </ faultstring > < detail /> </ soap:Fault > </ soap:Body >
如果Body元素的内容产生错误,必须包含错误消息的detail元素,但是如果文件头发生错误,则不能包含该元素 |