1

I am currently working on a SOAP request using VB.net. I found the code here WebService Send SOAP request and received response using visual Basic that I modified for my need.

Using Postman I have been able to establish a connection with the site (so I know it works). However, when I created this code, I am just receiving

Server did not recognize the value of HTTP Header SOAPAction

Error.

This is my 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
    
    
    'TODO: Change Header
    SoapStr = "<?xml version=""1.0"" encoding=""utf-8""?>"
    SoapStr = SoapStr & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
    SoapStr = SoapStr & "<soap:Header/>"
    
    
    SoapStr = SoapStr & "<soap:Body>"
    SoapStr = SoapStr & "<ACORD>"
    'I have the rest of the body in here
    SoapStr = SoapStr & "</ACORD>"
    SoapStr = SoapStr & "</soap:Body>"
    SoapStr = SoapStr & "</soap:Envelope>"

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

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


    Request.ContentType = "application/x-www-form-urlencoded"
    '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()
    MsgBox(SD2Request)

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

What am I missing? There aren't many resources for VB.net and SOAP. I would use C# but my company uses VB.net.

I took the C# code created out of PostMan and converted it to Vb. This is what I have, after fixing a few syntax errors.

Public Async Function SendSoapRequest() As Task(Of HttpWebRequestElement)

    Dim client = New HttpClient()
    Dim request = New HttpRequestMessage(HttpMethod.Post, "https://claimsearchgwa.iso.com/xmlsoap")
    request.Headers.Add("Cookie", "[CookieHere])
    Dim content = New StringContent("[ContentHere]")
    request.Content = content
    Dim response = Await client.SendAsync(request)
    response.EnsureSuccessStatusCode().ToString()
    'Console.WriteLine(Await .Content._)
    Return response

End Function

With this new code I am receiving this error:

Severity    Code    Description Project File    Line    Suppression State
Error (active)  BC30652 Reference required to assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' containing the type 'ConfigurationElement'. Add one to your project.   GNYLINYClaimsFUPWINSFileUpdate  \\njna3\sys\MIS\Projects\VisualStudio Projects\GNYLINYClaimsFUPWINSFileUpdate\GNYLINYClaimsFUPWINSFileUpdate\Module1.vb 426 
8
  • According to WebRequest documentation: WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead. Commented Aug 2, 2024 at 3:49
  • The following may be of interest: stackoverflow.com/questions/62987949/using-httpclient-with-soap Commented Aug 2, 2024 at 3:50
  • I would use C# but my company uses VB.net: You may consider writing it in C# first, then convert it to VB.NET. Commented Aug 2, 2024 at 4:24
  • From that post that you referenced, did you open the URL public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl in a browser and then search (Ctrl-F) for soapAction? Did you perform the same process for claimsearchgwa.iso.com/xmlsoap? When you modified the code, you didn't change the URL listed for soapAction. Commented Aug 2, 2024 at 4:27
  • @user246821 thank you for your help. I took the C# code that was generated out of PostMan and converted it to VB. This is what I am up to. I am greatful for any help you can give. Commented Aug 2, 2024 at 19:27

1 Answer 1

0

Your VB code looks fine.

In your question you provided two URLs:

Url 1 (Login Endpoint): https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl

Url 2 (Service Endpoint): https://claimsearchgwa.iso.com/xmlsoap

It looks like you has made a confusion between the endpoints provided. Bases in both WSDL, the first one apparently is a login endpoint and the second is the resource itself.

The header SOAPAction determines which resource you want to use

If you want to use the Login one, you have only one method to use, and it should be included in the header.

Your request should then look like this:

Url: https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl

SOAPAction: http://dpd.com/common/service/LoginService/2.0/getAuth

Body:

<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><your delisId></delisId>
         <password><your password></password>
         <messageLanguage>de_DE</messageLanguage>
      </ns:getAuth>
   </soapenv:Body>
</soapenv:Envelope>

In the second url you have two methods to use (SubmitToISO and VaildateSchema):

Your request should look like this if you want to use SubmitToISO:

URL: https://claimsearchgwa.iso.com/xmlsoap

SOAPAction: http://tempuri.org/SubmitToISO

Body:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header>
      <tem:ISOLogin>
         <tem:Username>your_user</tem:Username>
         <tem:Password>your_password</tem:Password>
      </tem:ISOLogin>
   </soapenv:Header>
   <soapenv:Body>
      <tem:SubmitToISO>
         <tem:Parameter1>value1</tem:Parameter1>
      </tem:SubmitToISO>
   </soapenv:Body>
</soapenv:Envelope>

And like this if you wnat to use VaildateSchema

URL: https://claimsearchgwa.iso.com/xmlsoap

SOAPAction: http://tempuri.org/VaildateSchema

Body:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header>
      <tem:ISOLogin>
         <tem:Username>your_user</tem:Username>
         <tem:Password>your_password</tem:Password>
      </tem:ISOLogin>
   </soapenv:Header>
   <soapenv:Body>
      <tem:VaildateSchema>
         <tem:Parameter1>param1</tem:Parameter1> 
      </tem:VaildateSchema>
   </soapenv:Body>
</soapenv:Envelope>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.