Silvia Parfeni
Silvia Parfeni

Reputation: 528

WebService Send SOAP request and received response using visual Basic

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:

enter image description here

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.

Upvotes: 3

Views: 38293

Answers (1)

wertyk
wertyk

Reputation: 408

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/")

Upvotes: 3

Related Questions