Note that there are some explanatory texts on larger screens.

plurals
  1. POPost XML to a web service
    primarykey
    data
    text
    <p>I have a web service, which accepts XML input. What I am trying to do is setup an aspx page which posts xml to the service. Here is my code so far, but I am getting an error 400 (bad request) when I try to submit...</p> <pre><code>Imports System.Net Imports System.IO Partial Class _Default Inherits System.Web.UI.Page Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click Dim strDataToPost As String Dim myWebRequest As WebRequest Dim myRequestStream As Stream Dim myStreamWriter As StreamWriter Dim myWebResponse As WebResponse Dim myResponseStream As Stream Dim myStreamReader As StreamReader ' Create a new WebRequest which targets the web service method myWebRequest = WebRequest.Create("http://foo/p09SoapHttpPort") ' Data to send strDataToPost = DataToSend.Text &amp; Server.UrlEncode(Now()) ' Set the method and content type With myWebRequest .Method = "POST" .ContentType = "text/xml" .Timeout = -1 .ContentLength = strDataToPost.Length() End With ' write our data to the Stream using the StreamWriter. myRequestStream = myWebRequest.GetRequestStream() myStreamWriter = New StreamWriter(myRequestStream) myStreamWriter.Write(strDataToPost) myStreamWriter.Flush() myStreamWriter.Close() myRequestStream.Close() ' Get the response from the remote server. myWebResponse = myWebRequest.GetResponse() ' Get the server's response status myResponseStream = myWebResponse.GetResponseStream() myStreamReader = New StreamReader(myResponseStream) ResponseLabel.Text = myStreamReader.ReadToEnd() myStreamReader.Close() myResponseStream.Close() ' Close the WebResponse myWebResponse.Close() End Sub End Class </code></pre> <p>If anyone knows of any good web resources on how to upload .xml files to a web service method that would also be a great help and would answer this question as I can re-work it that way.</p> <p>Thanks.</p> <p>P.S in the last edit, I modified the code to have .contentlength (thanks for the assistance). Unfortunately after this I am still getting 'Bad Request'. If anyone can confirm / disconfirm my code should be working, I will start investigating the service itself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload