Web services 调用Web服务失败
我得到了需要调用的Web服务的这种结构。 ws-name已设置为\u详细信息我正确设置,因此不会导致错误。 我想不出怎么解决这个问题。 当我调用它时,我得到一个错误: System.InvalidOperationException:Set_Details Web服务方法名称无效。System.Web.Services.Protocols.HttpServerProtocol.Initialize()处System.Web.Services.Protocols.ServerProtocolFactory.Create处System.Web.Services.Protocols.ServerProtocol.SetContext(类型、HttpContext上下文、HttpRequest请求、HttpResponse响应)处(类型类型、HttpContext上下文、HttpRequest请求、HttpResponse响应、布尔值和中止处理) *我将真实url路径更改为假地址,因此请忽略urlWeb services 调用Web服务失败,web-services,soap,asp-classic,Web Services,Soap,Asp Classic,我得到了需要调用的Web服务的这种结构。 ws-name已设置为\u详细信息我正确设置,因此不会导致错误。 我想不出怎么解决这个问题。 当我调用它时,我得到一个错误: System.InvalidOperationException:Set_Details Web服务方法名称无效。System.Web.Services.Protocols.HttpServerProtocol.Initialize()处System.Web.Services.Protocols.ServerProtocolFac
<?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>
这是我代表Web服务的班级
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"
当通过执行原始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>
web服务管道不知道该怎么做
您的web服务方法还接受一个复杂类型,Details
,因此您必须将请求作为HTTP POST和完整fat请求(信封、正文等)一起发送
您还需要在请求中设置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
。好的,我现在明白了,但不知道如何使用我当前的代码结构执行此操作-是否可能,或者我需要更改所有类?不要使用str构建XML串联。使用XML DOM创建XML。如果传入的数据包含诸如@AnthonyWJones之类的字符,这将确保正确的编码。我的答案纯粹是为了演示如何使基础工作正常,即如何调用从经典ASP/VBScript接受复杂类型的SOAP Web服务;添加另外10行XML即可我胡乱摆弄只会混淆答案。
<%
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
%>