I am learning web services and want to get this client working. I get the error "Cannot send a content-body with this verb-type" You can see I have set the method to "POST". The error comes when I try to execute the line with ws.getRequestStream. Any Ideas? Thanks.
Public Class Form1
Dim myUrl As String = "http://www.webserviceX.net"
Dim ws As System.Net.HttpWebRequest = System.Net.WebRequest.Create(myUrl)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
ws.Host = "www.webserviceX.net"
ws.Method = "POST"
ws.Timeout = 60000
ws.Accept = "text/xml"
ws.Headers.Add("SOAPAction", "http://www.webserviceX.NET/GetBookTitles")
' ws.ClientCertificates.Add
ws.ContentType = "text/xml; charset=""utf-8"""
Dim myxml As String = "<?xml version=""1.0"" encoding=""UTF-8""?>" & System.Environment.NewLine & _
"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & System.Environment.NewLine & _
"<soap:Body>" & System.Environment.NewLine & _
"<GetBookTitles xmlns=""http://www.webserviceX.NET"">" & System.Environment.NewLine & _
"</soap:Body>" & System.Environment.NewLine & _
"</soap:Envelope>"
Dim myencoder As New System.Text.ASCIIEncoding()
Dim myxmlByteArray() As Byte = myencoder.GetBytes(myxml)
ws.ContentLength = myxmlByteArray.Length
Dim postquerystream As System.IO.Stream = ws.GetRequestStream()
postquerystream.Write(myxmlByteArray, 0, myxmlByteArray.Length)
postquerystream.Close()
Dim response As System.Net.HttpWebResponse = ws.GetResponse()
If response.StatusCode = System.Net.HttpStatusCode.OK Then
Dim respstream As System.IO.StreamReader = New IO.StreamReader(ws.GetRequestStream())
Dim responsedata As String = respstream.ReadToEnd()
Me.TextBox1.Text = responsedata
End If
response.Close()
Catch ex As Exception
Dim x As String = ex.ToString
End Try
End Sub
End Class
Public Class Form1
Dim myUrl As String = "http://www.webserviceX.net"
Dim ws As System.Net.HttpWebRequest = System.Net.WebRequest.Create(myUrl)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
ws.Host = "www.webserviceX.net"
ws.Method = "POST"
ws.Timeout = 60000
ws.Accept = "text/xml"
ws.Headers.Add("SOAPAction", "http://www.webserviceX.NET/GetBookTitles")
' ws.ClientCertificates.Add
ws.ContentType = "text/xml; charset=""utf-8"""
Dim myxml As String = "<?xml version=""1.0"" encoding=""UTF-8""?>" & System.Environment.NewLine & _
"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & System.Environment.NewLine & _
"<soap:Body>" & System.Environment.NewLine & _
"<GetBookTitles xmlns=""http://www.webserviceX.NET"">" & System.Environment.NewLine & _
"</soap:Body>" & System.Environment.NewLine & _
"</soap:Envelope>"
Dim myencoder As New System.Text.ASCIIEncoding()
Dim myxmlByteArray() As Byte = myencoder.GetBytes(myxml)
ws.ContentLength = myxmlByteArray.Length
Dim postquerystream As System.IO.Stream = ws.GetRequestStream()
postquerystream.Write(myxmlByteArray, 0, myxmlByteArray.Length)
postquerystream.Close()
Dim response As System.Net.HttpWebResponse = ws.GetResponse()
If response.StatusCode = System.Net.HttpStatusCode.OK Then
Dim respstream As System.IO.StreamReader = New IO.StreamReader(ws.GetRequestStream())
Dim responsedata As String = respstream.ReadToEnd()
Me.TextBox1.Text = responsedata
End If
response.Close()
Catch ex As Exception
Dim x As String = ex.ToString
End Try
End Sub
End Class