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
soapAction? Did you perform the same process for claimsearchgwa.iso.com/xmlsoap? When you modified the code, you didn't change the URL listed forsoapAction.