0

我得到了需要调用的 Web 服务的这种结构。ws 名称是 Set_Details 我做对了,所以不会导致错误。我无法弄清楚如何解决这个问题。当我调用它时,我得到了错误:

System.InvalidOperationException:Set_Details Web 服务方法名称无效。在 System.Web.Services.Protocols.HttpServerProtocol.Initialize() 在 System.Web.Services.Protocols.ServerProtocol.SetContext(类型类型,HttpContext 上下文,HttpRequest 请求,HttpResponse 响应)在 System.Web.Services.Protocols.ServerProtocolFactory。创建(类型类型、HttpContext 上下文、HttpRequest 请求、HttpResponse 响应、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>

这是我调用类网络服务的代码

  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"
4

1 回答 1

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而是使用。

于 2012-06-16T03:48:02.487 回答