vb.net WebService 使用 Visual Basic 发送 SOAP 请求和接收响应
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32136293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WebService Send SOAP request and received response using visual Basic
提问by Silvia Parfeni
My customer give me a WebService url = https://public-ws-stage.dpd.com/services/LoginService/V2_0, he told me that, if I send this xml text:
我的客户给了我一个 WebService url = https://public-ws-stage.dpd.com/services/LoginService/V2_0,他告诉我,如果我发送这个 xml 文本:
but, this is not right if I use this code :
但是,如果我使用此代码,这是不对的:
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
don't return what my customer told, I don't understant the url is not true, oder I write a wrong code, Please help me.
不要返回我的客户告诉我的内容,我不明白 url 不是真的,否则我写了错误的代码,请帮助我。
采纳答案by wertyk
Try to change the URL without "?wsdl" from this:
尝试更改不带“?wsdl”的 URL:
Request = WebRequest.Create("https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl")
to this:
对此:
Request = WebRequest.Create("https://public-ws-stage.dpd.com/services/LoginService/V2_0/")