我的客户给了我一个 WebService url = https://public-ws-stage.dpd.com/services/LoginService/V2_0 ,他告诉我,如果我发送这个 xml 文本:

vb.net - WebService 使用 Visual Basic 发送 SOAP 请求和接收响应-LMLPHP

但是,如果我使用此代码,这是不对的:

Dim Request As WebRequest
Dim Response As WebResponse
Dim DataStream As Stream
Dim Reader As StreamReader
Dim SoapByte() As Byte
Dim SoapStr As String
Dim pSuccess As Boolean = True

SoapStr = "<?xml version=""1.0"" encoding=""utf-8""?>"
SoapStr = SoapStr & "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">"
SoapStr = SoapStr & "<soapenv:Header/>"
SoapStr = SoapStr & "<soapenv:Body>"
SoapStr = SoapStr & "<ns:getAuth> <delisId>id</delisId> <password>pass</password> <messageLanguage>de_DE</messageLanguage> </ns:getAuth>"
SoapStr = SoapStr & "</soapenv:Body>"
SoapStr = SoapStr & "</soapenv:Envelope>"

Try
  SoapByte = System.Text.Encoding.UTF8.GetBytes(SoapStr)

  Request = WebRequest.Create("https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl")
  Request.Headers.Add("SOAPAction", "https://public-ws-stage.dpd.com/services/LoginService/V2_0/getAuth")

  Request.ContentType = "text/xml; charset=utf-8"
  Request.ContentLength = SoapByte.Length
  Request.Method = "POST"

  DataStream = Request.GetRequestStream()
  DataStream.Write(SoapByte, 0, SoapByte.Length)
  DataStream.Close()

  Response = Request.GetResponse()
  DataStream = Response.GetResponseStream()
  Reader = New StreamReader(DataStream)
  Dim SD2Request As String = Reader.ReadToEnd()

  DataStream.Close()
  Reader.Close()
  Response.Close()

Catch ex As WebException
  MsgBox(ex.ToString())
End Try

不要返回我的客户告诉我的内容,我不明白 url 不是真的,否则我写了错误的代码,请帮助我。

最佳答案

尝试更改不带“?wsdl”的 URL:

Request = WebRequest.Create("https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl")

对此:
Request = WebRequest.Create("https://public-ws-stage.dpd.com/services/LoginService/V2_0/")

关于vb.net - WebService 使用 Visual Basic 发送 SOAP 请求和接收响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32136293/

10-14 10:24
查看更多