HttpWebRequest adding junk characters

Tech-Archive recommends: Speed Up your PC by fixing your registry



I am trying to invoke a remote Web Service that accepts XML data over https
but the server is returning a "The data at the root level is invalid. Line
1, position 1." error. I checked with the provider and he said that they
were receiving following on their server... Notice the weird junk characters
at the front...

<?xml version="1.0" encoding="utf-8"?>
<request><name>blah</blah><address>blah blah</address></request>

I checked the XML I am sending by writing it to a file instead of sending
over http and it was fine. I then created an ASP.NET web application that
took a request and wrote it out to a file. This also worked fine and there
were no junk characters in it. So I think the XML is being created correctly
and the only time there is a problem is when I am invoking a remote service
over https. Does anyone why the remote server is getting those junk
characters? Any suggestions are welcome...

I am using the following code to create my httpWebRequest

httpWebRequest = System.Net.WebRequest.Create(https://blah.blah.com)
httpWebRequest.Method = "POST"

httpWebRequest.ContentType = "text/xml"

Dim oProxy As WebProxy = WebProxy.GetDefaultProxy()

oProxy.Credentials = CredentialCache.DefaultCredentials

httpWebRequest.Proxy = oProxy

httpWebRequest.KeepAlive = False

httpWebRequest.ProtocolVersion = New System.Version("1.0")

httpWebRequest.Timeout = 12000


and following code to invoke the Web service

xmlWriter = New XmlTextWriter(httpRequest.GetRequestStream(),
System.Text.Encoding.UTF8)

With xmlWriter

..WriteStartDocument()

..WriteStartElement("request")

..WriteElementString("name", "blah")

..WriteElementString("address", "blah blah")

..WriteEndElement()

..WriteEndDocument()

..Flush()

..Close()

End With

xmlReader = New XmlTextReader(httpRequest.GetResponse().GetResponseStream())

Thanks in advance,

Sandeep






.



Relevant Pages

  • Re: Receiving xml problem
    ... I dont have an answer for you, but theres an example here that accepts XML ... data as a post submission and deserializes it in a web service. ... > The remote server returned an error: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: data transport
    ... in the Java world. ... I think you're describing developing a web service given a certain toolset that implements the standards. ... A small change to the interface will result in a new WSDL or whatever and your old server or old client will not simply ignore a new extraneous XML element received. ...
    (comp.lang.java.programmer)
  • BTS Synchronous WS request...Proxy Error
    ... transforms it to 35 MB of Xml and sendsthis Xml as string ... to a Web Service that calls a SQL Server store proc, ... development network environment i.e BizTalk Server, Web Service, SQL ...
    (microsoft.public.biztalk.general)
  • Re: Web service/soap/sql 2005
    ... pass over the data to the web service and have a stored procedure to ... The Web service could receive the XML data from the 3rd party, put the XML into a SQL server 2005 queue, have a SQL Server 2005 Broker Service running on SQL Server listening on the queue, pull the XML out of the queue, the SQL Broker Service parses the XML, and the SQL Server Broker Service calls the Stored Procedure. ... I have used SOAP Authentication on Web services that face the Internet, which means a client consuming the Web service must have a User-ID and PSW to access the Web service with text and XML being in a HTTPS transmission. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: SQLXMLBULKLOAD 3.0 Schema Stream
    ... > xml into SQL Server the first parameter of SQLXMLBulkLoad object is ... > to be able to send a stream. ... web service on the server, ...
    (microsoft.public.sqlserver.xml)