0

I have to make a soap request with the GET method for getting a login token.

This info i have recieve : full documentation : https://doc.dpd.be/node/34

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://dpd.com/common/service/types/LoginService/2.0">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:getAuth>
         <delisId>KD*****</delisId>
         <password>*******</password>
         <messageLanguage>en_EN</messageLanguage>
      </ns:getAuth>
   </soapenv:Body>
</soapenv:Envelope>

Sample Response

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <getAuthResponse xmlns="http://dpd.com/common/service/types/LoginService/2.1">
         <return>
            <delisId>SWSTEST</delisId>
            <customerUid>SWSTEST</customerUid>
            <authToken>GFadfGob14GWWgQcIldI6zYtuR7cyEHe2z6eWzb7BpFmcFvrzclRljlcV1OF</authToken>
            <depot>0530</depot>
            <authTokenExpires>2020-05-08T13:02:56.06</authTokenExpires>
         </return>
      </getAuthResponse>
   </soap:Body>
</soap:Envelope>

This is the code that i have so far, but how to send the enveloppe en ge a response ?

 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>KD3379602W</delisId> <password>207Yc*-K</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://wsshipper.dpd.be/soap/WSDL/LoginServiceV21.wsdl")
        Request.Headers.Add("SOAPAction", "http://dpd.com/common/service/types/LoginService/2.1")

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

????

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

End Sub
  • 1
    What about calling `Request.GetResponse()`? Aditionally this [question](https://stackoverflow.com/questions/4791794/client-to-send-soap-request-and-receive-response) has some nice answers. – Alex B. Nov 04 '20 at 11:10
  • I have try to use : Response = Request.GetResponse() but it returns a error : I get a error : content-length of chunked encoding cannot be set for an operation where no data is credited – Leffelaer Kristof Nov 05 '20 at 08:05
  • You have to acutally put some encoded data into the stream `using( var stream = Request .GetRequestStream() ) stream.Write( SoapByte , 0, SoapByte .Length );` – Alex B. Nov 05 '20 at 08:44
  • HTTP GET method does not send (and cannot send) data in the request body. Thus you cannot set ContentLength. You probably need to use the POST method call, set the ContentLength, as you're doing, and also write the data to the request stream. It could be a different method than POST is required, but that would be up to the server and I don't see the required method defined in the documentation you link to. – MarkL Nov 05 '20 at 17:33
  • On this page : https://doc.dpd.be/node/33 (last line before the image) says use the GET methode... i have try to use POST but i get the error this method ss not allowed – Leffelaer Kristof Nov 05 '20 at 21:39
  • I have asked dpd and it must be GET do someone have a example code to make a soap request in vb.net ? i can't find it ! I have dit a test with a online tester (boomerang in google chrome) and if i use POST then you get a 405 error, if you do this with GET you get a succes response. – Leffelaer Kristof Jan 19 '21 at 20:57

0 Answers0