我得到了这个需要调用的web服务结构。 ws名称是Set_Details我把它弄好了,所以不能导致错误。 我无法弄清楚如何解决这个问题。 当我打电话给它时我得到了错误:
System.InvalidOperationException:Set_Details Web服务方法名称无效。在System.Web.Services.Protocols.Protocol.Partocol.Potocol.Potocol.Partocol.Potocol.Pit上的System.Web.Services.Protocols.HttpServerProtocol.Initialize()处于System.Web.Services.Protocols.Protocol.SetContext(Type类型,HttpContext上下文,HttpRequest请求,HttpResponse响应)。 Create(Type type,HttpContext context,HttpRequest request,HttpResponse response,Boolean& abortProcessing)
*我将真实网址路径更改为虚假地址,因此请忽略网址
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<Set_Details xmlns="http://ws.blobobobo.uk/WebService/">
<Details>
<Number>int</Number>
<Category>string</Category>
</Details>
<LoginID>string</LoginID>
<LoginPassword>string</LoginPassword>
</Set_Details>
</soap:Body>
</soap:Envelope>
这是我的代码,我称之为类webservice
dim ws
set ws = new webservice
ws.url = mainip
ws.method = "Set_OrderDetails"
ws.parameters.Add "Number", "6166""
ws.parameters.Add "Category", "ffff"
ws.parameters.Add "LoginID", "ex10"
ws.parameters.Add "LoginPassword", "ex20"
ws.execute
response.write ws.response
set ws = nothing
这是我的代表网络服务的课程
class WebService
public Url
public Method
public Response
public Parameters
public function execute()
dim xmlhttp
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "POST", Url & "/" & Method, false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send Parameters.toString
response = xmlhttp.responseText
set xmlhttp = nothing
end function
Private Sub Class_Initialize()
Set Parameters = new wsParameters
End Sub
Private Sub Class_Terminate()
Set Parameters = Nothing
End Sub
end class
class wsParameters
public mCol
public function toString()
dim nItem
dim buffer
buffer = ""
for nItem = 1 to Count
buffer = buffer & Item(nItem).toString & "&"
next
if right(buffer,1)="&" then
buffer = left(buffer,len(buffer)-1)
end if
toString = buffer
end function
public sub Clear
set mcol = nothing
Set mCol = CreateObject("Scripting.Dictionary")
end sub
public sub Add(pKey,pValue)
dim newParameter
set newParameter = new wsParameter
newParameter.Key = pKey
newParameter.Value = pValue
mCol.Add mCol.count+1, newParameter
set newParameter = nothing
end sub
public function Item(nKey)
set Item=mCol.Item(nKey)
end function
public function ExistsXKey(pKey)
dim nItem
for nItem = 1 to mcol.count
if mCol.Item(nItem).key = pKey then
ExistsXKeyword = true
exit for
end if
next
end function
public sub Remove(nKey)
mCol.Remove(nKey)
end sub
public function Count()
Count=mCol.count
end function
Private Sub Class_Initialize()
Set mCol = CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate()
Set mCol = Nothing
End Sub
end class
class wsParameter
public Key
public Value
public function toString()
toString = Key & "=" & Value
end function
end class
Dim ip
mainip="http://ws.bloblobo.uk/WebServices/ws.asmx"
答案 0 :(得分:0)
通过执行原始HTTP POST调用SOAP Web服务方法时,您应该构建并发送Web服务所描述的整个请求。即你需要发送:
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<Set_Details xmlns="http://ws.blobobobo.uk/WebService/">
<Details>
<Number>6166</Number>
<Category>ffff</Category>
</Details>
<LoginID>ex10</LoginID>
<LoginPassword>ex20</LoginPassword>
</Set_Details>
</soap:Body>
</soap:Envelope>
目前你正在发帖:
Number=6166&Category=ffff&LoginID=ex10&LoginPassword=ex20
Web服务管道层不知道如何处理它。
您的Web服务方法也接受复杂类型Details
,因此您必须将请求作为HTTP POST和完整的胖请求(信封,正文等)发送。
您还需要在请求中设置SOAPAction
HTTP标头,例如:
SOAPAction: "http://ws.blobobobo.uk/WebService/Set_Details"
<强>更新强>
这是一个完全有效的例子:
<%
result = Set_Details(6166, "ffff", "ex10", "ex20")
Response.Write result
Function Set_Details(number, category, loginID, loginPassword)
Dim request, doc, xmlHttp, url
url = "http://ws.bloblobo.uk/WebServices/ws.asmx"
request = "<?xml version='1.0' encoding='utf-8'?>" & _
"<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/'>" & _
" <soap:Body>" & _
" <Set_Details xmlns='http://ws.blobobobo.uk/WebService/'>" & _
" <Details>" & _
" <Number>" & number & "</Number>" & _
" <Category>" & category & "</Category>" & _
" </Details>" & _
" <LoginID>" & loginID & "</LoginID>" & _
" <LoginPassword>" & loginPassword & "</LoginPassword>" & _
" </Set_Details>" & _
" </soap:Body>" & _
"</soap:Envelope>"
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlHttp.open "POST", url, False
xmlHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlHttp.setRequestHeader "SOAPAction", _
"""http://ws.blobobobo.uk/WebService/Set_Details"""
xmlHttp.send request
Set response = xmlHttp.responseXML
'' The presumption here is that you get some kind of result back.
'' The example here assumes that the `Set_Details` method returns a simple type
'' such as a string, number or boolean
result = response.documentElement.selectSingleNode("//Set_DetailsResult").text
Set_Details = result
End Function
%>
最后从不使用Microsoft.XMLHTTP
发出HTTP请求,它不打算用于ASP或服务器端应用程序,而是使用MSXML2.ServerXMLHTTP
。