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

HTML网页中调用 方法

〈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服务

ASP中调用方法(SOAP方式)

 1   
 2Dim url,xmlhttp,dom,node,xmlDOC   
 3'根据webservice的测试页不同的方法构造不同的soap request   
 4SoapRequest = "  "& _   
 5"  "xmlns:xsd="&CHR(34)&"http://www.w3.org/2001/XMLSchema"&CHR(34)&" "& _   
 6"xmlns:soap="&CHR(34)&"http://schemas.xmlsoap.org/soap/envelope/"&CHR(34)&">"& _   
 7"  "& _   
 8"  "& _   
 9"  311  "& _   
10"  "& _   
11"  "& _   
12" "   
13url = "http://www.ydcom.net/service/S_COMM.asmx?methodname=GetCZID"   
14Set xmlDOC =server.CreateObject("MSXML.DOMDocument")   
15xmlDOC.loadXML(SoapRequest)   
16Set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")   
17xmlhttp.Open "POST",url,false   
18xmlhttp.setRequestHeader "Content-Type", "text/xml;charset=utf-8"   
19xmlhttp.setRequestHeader "SOAPAction", "http://www.ydcom.net/service/SrvCOMM/S_COMM/GetCZID"   
20xmlhttp.setRequestHeader "Content-Length",LEN(SoapRequest)   
21xmlhttp.Send(xmlDOC) 
22
23If xmlhttp.Status = 200 Then   
24xmlDOC.load(xmlhttp.responseXML)   
25Response.Write xmlhttp.Status&"   
26"   
27Response.Write xmlhttp.StatusText&"   
28执行结果为:"   
29Response.Write xmlDOC.getElementsByTagName("GetCZIDResult")(0).text   
30else   
31Response.Write xmlhttp.Status&"   
32"   
33Response.Write xmlhttp.StatusText   
34end if   

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

说明:总的来讲采用webservice的列表页说明来构造不同的SoapRequest,然后,
从返回xmlDoc中取返回值xmlDOC.getElementsByTagName

ASP中调用方法(HTTP方式)

 1   
 2Set objHTTP = Server.CreateObject("MSXML2.XMLHTTP")   
 3Set xmlDOC =Server.CreateObject("MSXML.DOMDocument")   
 4strWebserviceURL = "http://www.ydcom.net/service/S_COMM.asmx/GetCZID"   
 5'设置参数及其值   
 6strRequest = "sTypeNum=311"   
 7objHTTP.Open "POST", strWebserviceURL, False   
 8'设置这个Content-Type很重要   
 9objHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"   
10objHTTP.SetRequestHeader("Content-Length: 30")   
11objHTTP.Send(strRequest)   
12bOK = xmlDOC.load(objHTTP.responseXML)   
13'看看状态值   
14if objHTTP.Status=200 then   
15xmlStr = xmlDOC.xml   
16Response.Write xmlStr   
17else   
18Response.Write objHTTP.Statu&"   
19"   
20Response.Write objHTTP.StatusText   
21end if   

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

VB6中调用方法

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消息
h.open "POST", "http://localhost/TestWebService/Service1.asmx", False
h.setRequestHeader "Content-Type", "text/xml"
h.send (strxml)
While h.readyState <> 4
Wend
'显示返回的XML信息
Text1.Text = h.responseText
'将返回的XML信息解析并且显示返回值
Set x = New MSXML2.DOMDocument40
x.loadXML Text1.Text
Text1.Text = x.childNodes(1).Text

VB.NET中调用方法

1,首先添加web引用,地址为: http://www.ydcom.net/service/s_comm.asmx

2,定义:dim sCom as New net.ydcom.www.S_COMM

3,调用:dim strCZID as string = sComm.GetCZID("313")

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

PB.NET(PB9)中调用方法

SoapConnection conn
Test_wsservice1soap sCom
long rVal
//string str_endpoint
//str_endpoint = " http://www.ydcom.net/service/s_comm.asmx?WSDL "
conn = create SoapConnection
rVal = Conn.CreateInstance(sCom, "test_wsservice1soap")
sle_1.text = sCom.GetCZID("313"))
destroy conn

Published At
Categories with Web编程
Tagged with
comments powered by Disqus