views:

552

answers:

2

Hello i'm developing a .net application which consumes a java web service, i created the client through wsdl.exe tool and its working fine, one of the method of the web service, receives an xml document as a parameter, and im using an XmlTextWriter to generate the document, but im having problems when including special characters inside the xml document for example:

The document im generating looks like this:

<xml-parameter>
  <some-field> this is text whit a (>) charatcer</some-field>
</xml-parameter>

Using fliddler to inspect the generated request, i see that its begin escaped like this:

&lt;xml-parameter&gt;
  &lt;some-field&gt; this is a text whit a (&amp;gt;) character $lt;/some-field&gt;
&lt;xml-parameter&gt;

I can see is beign escaped as "& amp;gt;" instead of &gt ; i all ready tried using the entity instead of the actual character whit no luck thanks in advance =).

Edit: here's the code is use to generate the xml, basically i use a memory stream and xmltextwriter to generate xml and then read the whole stream, i pass the generated xml to my service proxy.

string query = "/AGS_Polizas/INBOUNDLINK/@SOURCEITEMREF = > * ";

        MemoryStream stream = new MemoryStream();
        XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);
        writer.Formatting = Formatting.Indented;
        writer.Indentation = 4;
        writer.WriteStartDocument(true);
        writer.WriteStartElement("RunQueryRequest");
        writer.WriteAttributeString("xmlns", "http://www.ibm.com/xmlns/db2/cm/beans/1.0/schema");
        writer.WriteAttributeString("maxResults", "0");
        writer.WriteAttributeString("version", "latest-version(.)");
        writer.WriteAttributeString("contentOption", "URL");
        writer.WriteAttributeString("retrieveOption", "ITEMTREE");

        writer.WriteStartElement("AuthenticationData");
        writer.WriteAttributeString("connectString", "SCHEMA=ICMADMIN");
        writer.WriteAttributeString("configString", "");

        writer.WriteStartElement("ServerDef");

        writer.WriteStartElement("ServerType");
        writer.WriteString("ICM");
        writer.WriteEndElement();

        writer.WriteStartElement("ServerName");
        writer.WriteString("icmnlsdb");
        writer.WriteEndElement();

        writer.WriteEndElement();


        writer.WriteStartElement("LoginData");

        writer.WriteStartElement("UserID");
        writer.WriteString("icmadmin");
        writer.WriteEndElement();

        writer.WriteStartElement("Password");
        writer.WriteString("Passw0rd");
        writer.WriteEndElement();

        writer.WriteEndElement();            
        writer.WriteEndElement();

        writer.WriteStartElement("QueryCriteria");
        writer.WriteStartElement("QueryString");
        writer.WriteString(query);
        writer.WriteEndElement();

        writer.WriteEndElement();


        writer.WriteEndElement();

        writer.Flush();

        stream.Seek(0, SeekOrigin.Begin);
        StreamReader reader = new StreamReader(stream);
        string xml = reader.ReadToEnd();
        writer.Close();
        reader.Close();
A: 

Why are you generating the request xml by hand and not using .NET's built-in method for consuming web services?

It seems like the > *should be double-escaped. The ">" sign needs to be escaped to be included in your xml doc. Then your entire XML doc needs to be escaped to fit into the XML web service request. I don't think the escaping is necessarily a problem.

Yoenhofen
Yes and no, believe it or not, i'm consuming a web service which has only 1 method "processXMLRequest",so my generated proxy has only 1 method "processXMLRequest" which receives an xml string, so although im not creating the SOAP request, i still need to create the xml request which the web service understands, quite a redundant web service indeed =(
Harima555
Yeah, then the > sign should definitely be double-escaped. Once to fit into the xmlRequest, and once in the SOAP request.What do you see in the debugger inside of the web method?
Yoenhofen
Harima555
Yoenhofen
A: 

Ok so i managed to resolve this by replacing the ">" on the xml the XmlTextWriter generates and letting the service proxy escape the whole SOAP request.

Harima555