all groups > dotnet web services > june 2007 >
You're in the

dotnet web services

group:

WebClient generates exception: header must be modified using ...


WebClient generates exception: header must be modified using ... oldVB3r
6/22/2007 1:45:25 PM
dotnet web services:
The following code generates the exception shown below when I call
UploadData. I'm trying to call a WCF service using basicHTTP with a manually
generated Soap message. Am I on the right track with this code? Thanks!!

Code:

Dim recvDoc As New Xml.XmlDocument
recvDoc.LoadXml("<s:Envelope> ... Soap XML goes here")

Dim wc As New System.Net.WebClient()
With wc
Dim str() As Byte =
System.Text.Encoding.UTF8.GetBytes(recvDoc.OuterXml)

.Encoding = System.Text.Encoding.UTF8
.Headers.Add(Net.HttpRequestHeader.ContentType, "text/xml")
.Headers.Add(Net.HttpRequestHeader.ContentLength,
str.GetLength(0).ToString)
.Headers.Add(Net.HttpRequestHeader.Accept, "*/*")
.Headers.Add(Net.HttpRequestHeader.KeepAlive, "1")

Dim respStr As String =
System.Text.Encoding.UTF8.GetString(wc.UploadData("http://localhost/DevWcf/WcfSimpleTest/WcfSimpleTest.svc", str))

Dim respDoc As New Xml.XmlDocument
respDoc.LoadXml(respStr)
End With

Exception:
"This header must be modified using the appropriate property. Parameter
RE: WebClient generates exception: header must be modified using ... oldVB3r
6/25/2007 1:03:01 PM
I wasn't able to resolve this issue. I would still like to know what is cause
the exception but here is a workaround for anyone interested:
Dim respDoc As New Xml.XmlDocument
Dim str() As Byte = System.Text.Encoding.UTF8.GetBytes("<?xml
version='1.0' encoding='utf-8'?> soap envelope goes here")
Dim wr As System.Net.HttpWebRequest =
System.Net.WebRequest.Create("http://localhost/DevWcf/WcfSimpleTest/WcfSimpleTest.svc")
With wr
.Method = "POST"
.KeepAlive = True
.Accept = "text/xml"
.ContentLength = str.Length
.ContentType = "text/xml; charset=utf-8"
.Headers.Add("SOAPAction",
"http://tempuri.org/ISimpleTest/SimpleOperation")

Dim st As IO.Stream = .GetRequestStream()
st.Write(str, 0, str.Length)
st.Close()

Try
Dim res As Net.WebResponse = .GetResponse
Dim resSt As IO.Stream = res.GetResponseStream
Dim doc As String = New IO.StreamReader(resSt).ReadToEnd
respDoc.LoadXml(doc)

Catch ex As Exception
... do exception handling here ...
End Try
AddThis Social Bookmark Button