如何在各种开发语言中调用web service[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 goodym 的 blog

方法

〈form target="_blank" action='http://www.ydcom.net/service/s_comm.asmx/getczid' method="post"〉
〈table cellspacing="0" cellpadding="4" frame="box" bordercolor="#dcdcdc" rules="none" style="border-collapse: collapse;"〉
〈tr〉
〈td class="frmheader" background="#dcdcdc" style="border-right: 2px solid white;"〉参数〈/td〉
〈td class="frmheader" background="#dcdcdc"〉值〈/td〉
〈/tr〉
〈tr〉
〈td class="frmtext" style="color: #000000; font-weight: normal;"〉stypenum:〈/td〉
〈td〉〈input class="frminput" type="text" size="50" name="stypenum"〉〈/td〉
〈/tr〉
〈tr〉
〈td〉〈/td〉
〈td align="right"〉 〈input type="submit" value="调用" class="button"〉〈/td〉
〈/tr〉
〈/table〉
〈/form〉

实例:如何调用服务产生18位关键值

相关文档: 使用vbscript脚本调用web服务


<%
dim url,xmlhttp,dom,node,xmldoc
'根据webservice的测试页不同的方法构造不同的soap request
soaprequest = ""& _
""xmlns:xsd="&chr(34)&"http://www.w3.org/2001/xmlschema"&chr(34)&" "& _
"xmlns:soap="&chr(34)&"http://schemas.xmlsoap.org/soap/envelope/"&chr(34)&">"& _
""& _
""& _
"311"& _
"
"& _
"
"& _
"
"
url = "http://www.ydcom.net/service/s_comm.asmx?methodname=getczid"
set xmldoc =server.createobject("msxml.domdocument")
xmldoc.loadxml(soaprequest)
set xmlhttp = server.createobject("msxml2.xmlhttp")
xmlhttp.open "post",url,false
xmlhttp.setrequestheader "content-type", "text/xml;charset=utf-8"
xmlhttp.setrequestheader "soapaction", "http://www.ydcom.net/service/srvcomm/s_comm/getczid"
xmlhttp.setrequestheader "content-length",len(soaprequest)
xmlhttp.send(xmldoc)

if xmlhttp.status = 200 then
xmldoc.load(xmlhttp.responsexml)
response.write xmlhttp.status&"
"
response.write xmlhttp.statustext&"
执行结果为:"
response.write xmldoc.getelementsbytagname("getczidresult")(0).text
else
response.write xmlhttp.status&"
"
response.write xmlhttp.statustext
end if
%>

实例:如何使用asp调用服务产生18位关键值 asp源文件代码

说明:总的来讲采用webservice的列表页说明来构造不同的soaprequest,然后,
从返回xmldoc中取返回值xmldoc.getelementsbytagname


<%
set objhttp = server.createobject("msxml2.xmlhttp")
set xmldoc =server.createobject("msxml.domdocument")
strwebserviceurl = "http://www.ydcom.net/service/s_comm.asmx/getczid"
'设置参数及其值
strrequest = "stypenum=311"
objhttp.open "post", strwebserviceurl, false
'设置这个content-type很重要
objhttp.setrequestheader "content-type", "application/x-www-form-urlencoded"
objhttp.setrequestheader("content-length: 30")
objhttp.send(strrequest)
bok = xmldoc.load(objhttp.responsexml)
'看看状态值
if objhttp.status=200 then
xmlstr = xmldoc.xml
response.write xmlstr
else
response.write objhttp.statu&"
"
response.write objhttp.statustext
end if
%>

实例:如何使用asp调用服务产生18位关键值 asp源文件代码


dim strxml as string
dim str as string
str = text2.text
'定义soap消息
strxml = "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/'>" & str &
"
"
'定义一个http对象,一边向服务器发送post消息
dim h as msxml2.serverxmlhttp40
'定义一个xml的文档对象,将手写的或者接受的xml内容转换成xml对象
dim x as msxml2.domdocument40
'初始化xml对象
set x = new msxml2.domdocument40
'将手写的soap字符串转换为xml对象
x.loadxml strxml
'初始化http对象
set h = new msxml2.serverxmlhttp40
'向指定的url发送post消息

本文关键:如何在各种开发语言中调用web service
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top