本文介绍了WebService 使用 Visual Basic 发送 SOAP 请求并收到响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的客户给我一个 WebService url =
但是,如果我使用此代码,这是不对的:
Dim Request As WebRequestDim Response 作为 WebResponseDim DataStream 作为流Dim Reader 作为 StreamReaderDim SoapByte() As ByteDim SoapStr 作为字符串Dim pSuccess As Boolean = TrueSoapStr = "<?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:信封>"尝试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.LengthRequest.Method = "POST"DataStream = Request.GetRequestStream()DataStream.Write(SoapByte, 0, SoapByte.Length)数据流.关闭()响应 = Request.GetResponse()数据流 = Response.GetResponseStream()读者 = 新的 StreamReader(DataStream)Dim SD2Request As String = Reader.ReadToEnd()数据流.关闭()Reader.Close()Response.Close()将 ex 作为 WebException 捕获MsgBox(ex.ToString())结束尝试
不要返回我的客户告诉我的内容,我不明白 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/")
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:
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.
解决方案
Try to change the URL without "?wsdl" from this:
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/")
这篇关于WebService 使用 Visual Basic 发送 SOAP 请求并收到响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!