views:

187

answers:

3

From my Windows Service I am passing a well-formed XML string to a Java Web Service.

The Java Web Service will process the data and return me a status code. Though I am passing a well formatted XML file. I am getting an error from the Java Web Service of:

Invalid byte 1 of 1 utf-8 sequence in vb.net

What is the reason for this?


Transferred from answer by author:

Sorry for not providing more details. Here is the sample XML I am generating from VB.net Windows service and there are CDATA tags for a few elements.

<?xml version="1.0" encoding="utf-8"?>
<bookstore>
  <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
  <book category="CHILDREN">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="WEB">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>

I am passing the above XML to the Java Web Service.

The XML received by the Java Application though is not cleanly formatted. For some reason few closing tags are broken and appearing in next line.

For example:

<book category="WEB">
        <title lang="en">Learning XML</tit
le>
        <author>Erik T. Ray</aut
hor>
        <year>2003</year>
        <price>39.95</price>
      </book>

Could this be part of the trouble?

A: 

Can't really say anything for sure without more details, but are you sure that the input is UTF-8? It sounds to me like you might passing in UTF-16/UCS-2 data, which will have a 0 for bytes 1,3,5,7,...

Tim Sylvester
A: 

Sorry for not providing more details. Here is the sample xml I am generating from VB.net windows service and there are CDATA tags for few elements.

<?xml version="1.0" encoding="utf-8"?>
<bookstore>
  <book category="COOKING">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <year>2005</year>
    <price>30.00</price>
  </book>
  <book category="CHILDREN">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book category="WEB">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
    <year>2003</year>
    <price>39.95</price>
  </book>
</bookstore>

I am passing the above xml to the Java Web service.

The xml received by the Java Application though is not cleanly formated. For some reason few closing tags are broken and appearing in next line.

For example

<book category="WEB">
        <title lang="en">Learning XML</tit
le>
        <author>Erik T. Ray</aut
hor>
        <year>2003</year>
        <price>39.95</price>
      </book>
Please edit your question rather than providing the extra information as an 'answer'. Now I've done that for you, please remove (delete) this 'answer'. Thanks.
Jonathan Leffler
A: 

How are you sending the data to the web service?

If its a loop of some sort what API are you using to write to the connection? Make sure you're using the .write()-style method instead of .writeln()-style method.

devstuff
I am building the xml using xmlwriter in vb.net to a streamreader and then passing the string as parameter to the Java Web service