我被給了這個我需要調用的web服務的結構。 ws的名字是Set_Details我把它弄錯了,所以不能導致錯誤。 我無法弄清楚如何解決這個問題。 當我叫它我得到錯誤:未能調用web服務
System.InvalidOperationException:Set_Details Web服務方法名稱無效。在System.Web.Services.Protocols.ServerProtocol.SetContext(類型類型,HttpContext上下文,HttpRequest請求,HttpResponse響應)System.Web.Services.Protocols.ServerProtocolFactory上System.Web.Services.Protocols.HttpServerProtocol.Initialize()。創建(類型類型,HttpContext的背景下,HttpRequest對象的要求,HttpResponse對象響應,布爾& abortProcessing)
*我改變了真實的URL路徑,假地址,請忽略網址
<?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>
這是我的代碼,我致電課程網上服務
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
這是我的課誰代表了Web服務
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"
好吧我現在明白,但不知道如何做到這一點與我目前的代碼結構 - 是否可能或我需要改變所有類? – Bobo2012
@ Bobo2012 - 我提供了一個完整的例子。 – Kev
不要使用字符串連接來構建XML。使用XML DOM來創建XML。如果傳入數據包含諸如'<'和'&'的字符,這將確保正確的編碼。它還將確保XML的格式良好。 – AnthonyWJones