title: VB using SOAP & XML for web services
body: <p>I am trying to perform a XML Soap call in a VB application to a web service.  I can get this to work using SoapUI and XMLSpy, which leads me to believe that the XML is correct.  When I perform the code I get an error 500 Server Internal Error.  Which leads me to believe I am missing something in the code and not in the XML.  I did try adding a Server Reference, but that didn't seem to help either.</p>
  
  <p>I used this video as a reference: <a href="https://www.youtube.com/watch?v=FE4PdSnox1w/%22Visual%20Basic%20-%20WebRequests%20[VB.net]%20[Intermediate]%22" rel="nofollow noreferrer">"Visual Basic - WebRequests VB.net Intermediate"</a>
  My code looks like this:</p>
  
  <pre><code>Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  
      Dim SoapByte() As Byte
      Dim SoapStr As String = ""
      SoapStr = SoapStr &amp; "&lt;?xml version=""1.0"" encoding=""UTF-8""?&gt;"
      SoapStr = SoapStr &amp; "&lt;soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:web=""http://webservice.lme.com""&gt;"
      SoapStr = SoapStr &amp; "&lt;soapenv:Header/&gt;"
      SoapStr = SoapStr &amp; "&lt;soapenv:Body&gt;"
      SoapStr = SoapStr &amp; "&lt;web:getCustomerRate&gt;"
      SoapStr = SoapStr &amp; "&lt;web:criIn&gt;"
      SoapStr = SoapStr &amp; "&lt;web:protectFreeze&gt;Y&lt;/web:protectFreeze&gt;"
      SoapStr = SoapStr &amp; "&lt;web:accountNumber&gt;226744&lt;/web:accountNumber&gt;"
      SoapStr = SoapStr &amp; "&lt;web:callConsgBfrDel&gt;No&lt;/web:callConsgBfrDel&gt;"
      SoapStr = SoapStr &amp; "&lt;web:callforAppmnt&gt;No&lt;/web:callforAppmnt&gt;"
      SoapStr = SoapStr &amp; "&lt;web:callforCarrierConv&gt;No&lt;/web:callforCarrierConv&gt;"
      SoapStr = SoapStr &amp; "&lt;web:COD&gt;N&lt;/web:COD&gt;"
      SoapStr = SoapStr &amp; "&lt;web:CODAmount&gt;0&lt;/web:CODAmount&gt;"
      SoapStr = SoapStr &amp; "&lt;web:CODPayTerms&gt;0&lt;/web:CODPayTerms&gt;"
      SoapStr = SoapStr &amp; "&lt;!--1 or more repetitions:--&gt;"
      SoapStr = SoapStr &amp; "&lt;web:commLines&gt;"
      SoapStr = SoapStr &amp; "&lt;web:commClass&gt;100&lt;/web:commClass&gt;"
      SoapStr = SoapStr &amp; "&lt;web:commweight&gt;1000&lt;/web:commweight&gt;"
      SoapStr = SoapStr &amp; "&lt;/web:commLines&gt;"
      SoapStr = SoapStr &amp; "&lt;web:customerType&gt;S&lt;/web:customerType&gt;"
      SoapStr = SoapStr &amp; "&lt;web:destCity&gt;Lake City&lt;/web:destCity&gt;"
      SoapStr = SoapStr &amp; "&lt;web:destState&gt;MN&lt;/web:destState&gt;"
      SoapStr = SoapStr &amp; "&lt;web:destZip&gt;55041&lt;/web:destZip&gt;"
      SoapStr = SoapStr &amp; "&lt;web:fullValueCoverage&gt;No&lt;/web:fullValueCoverage&gt;"
      SoapStr = SoapStr &amp; "&lt;web:fvcAmount&gt;0&lt;/web:fvcAmount&gt;"
      SoapStr = SoapStr &amp; "&lt;web:hazMat&gt;N&lt;/web:hazMat&gt;"
      SoapStr = SoapStr &amp; "&lt;web:insideDel&gt;No&lt;/web:insideDel&gt;"
      SoapStr = SoapStr &amp; "&lt;web:insidePckup&gt;No&lt;/web:insidePckup&gt;"
      SoapStr = SoapStr &amp; "&lt;web:lftgtReqDel&gt;No&lt;/web:lftgtReqDel&gt;"
      SoapStr = SoapStr &amp; "&lt;web:lftgtRqrdPckup&gt;No&lt;/web:lftgtRqrdPckup&gt;"
      SoapStr = SoapStr &amp; "&lt;web:lmtAccessDel&gt;No&lt;/web:lmtAccessDel&gt;"
      SoapStr = SoapStr &amp; "&lt;web:lmtdAccessPckup&gt;No&lt;/web:lmtdAccessPckup&gt;"
      SoapStr = SoapStr &amp; "&lt;web:origCity&gt;Burnsville&lt;/web:origCity&gt;"
      SoapStr = SoapStr &amp; "&lt;web:origState&gt;MN&lt;/web:origState&gt;"
      SoapStr = SoapStr &amp; "&lt;web:origZip&gt;55337&lt;/web:origZip&gt;"
      SoapStr = SoapStr &amp; "&lt;web:palletCount&gt;1&lt;/web:palletCount&gt;"
      SoapStr = SoapStr &amp; "&lt;web:palletType&gt;PALLETS&lt;/web:palletType&gt;"
      SoapStr = SoapStr &amp; "&lt;web:password&gt;&lt;/web:password&gt;"
      SoapStr = SoapStr &amp; "&lt;web:paymentType&gt;P&lt;/web:paymentType&gt;"
      SoapStr = SoapStr &amp; "&lt;web:prvtRsdncDel&gt;No&lt;/web:prvtRsdncDel&gt;"
      SoapStr = SoapStr &amp; "&lt;web:prvtRsdncPckup&gt;No&lt;/web:prvtRsdncPckup&gt;"
      SoapStr = SoapStr &amp; "&lt;web:shipDate&gt;10/02/2017&lt;/web:shipDate&gt;"
      SoapStr = SoapStr &amp; "&lt;web:usePalletPricing&gt;No&lt;/web:usePalletPricing&gt;"
      SoapStr = SoapStr &amp; "&lt;web:username&gt;&lt;/web:username&gt;"
      SoapStr = SoapStr &amp; "&lt;/web:criIn&gt;"
      SoapStr = SoapStr &amp; "&lt;/web:getCustomerRate&gt;"
      SoapStr = SoapStr &amp; "&lt;/soapenv:Body&gt;"
      SoapStr = SoapStr &amp; "&lt;/soapenv:Envelope&gt;"
      goUrl.Text = "Http://www.lme4me.com:80/webapp/CustomPricing/services/CRIMethods"
  
      Try
  
          SoapByte = Encoding.UTF8.GetBytes(SoapStr)
  
          'Create initial request
          Dim request As HttpWebRequest = HttpWebRequest.Create(goUrl.Text)
          request.Proxy = Nothing 'Speeds up the request by setting the proxies to nothing
          request.UserAgent = "Test" 'We should not be worried about this.
          request.PreAuthenticate = False
          request.Method = "POST"
          request.ContentType = "Text/ Xml;charset=UTF-8"
          'request.Headers.Add("SOAPAction", "http://www.lme4me.com:80/webapp/CustomPricing/services/CRIMethods/getCustomerRate")
          request.Headers.Add("SOAPAction", "getCustomerRate")
  
          'request.ContentLength = 2215
          request.Host = "www.lme4me.com:80"
          'request.Connection = "Keep-Alive"
          request.UserAgent = "Apache-HttpClient / 4.1.1 (java 1.5)"
  
          'Create the Response and reader
          Dim response As HttpWebResponse = request.GetResponse()
          Dim responseHdr As String = request.GetResponse.ResponseUri.ToString()
          Dim responseStream As IO.Stream = response.GetResponseStream()
          'Create a new Stream reader
          Dim streamReader As New System.IO.StreamReader(responseStream)
          Dim Data As String = streamReader.ReadToEnd
  
          streamReader.Close()
  
          ' Display the Data on the screen
          UrlResponseText.Text = Data
  
      Catch ex As WebException
  
          MsgBox("Inproper input: " + Err.Description)
          goUrl.Text = ""
          If (ex.Status = WebExceptionStatus.ProtocolError) Then
              Dim error1 As String = New IO.StreamReader(ex.Response.GetResponseStream()).ReadToEnd()
              MsgBox("Rest of Error: " + error1.ToString())
          End If
      End Try
  
  End Sub
  
  Private Sub goUrl_TextChanged(sender As Object, e As EventArgs) Handles goUrl.TextChanged
  
  End Sub
  </code></pre>
  
  <p>End Class</p>
  
  <p>I can not seem to find much help for doing this in Visual Basic / VB. </p>