0

I'm working with a third party web service and am having problems sending data from my .Net application. Scenario:

I connect to their server using HttpClient. I get back a security token that gets appended to the end of the request, which is also send using HttpClient.

Here's an update statement that gets sent to the server:

<?xml version="1.0" encoding="utf-8" ?>
<NODES_OPERATIONS>
    <ChangeNode URL="C294785" >
        <ChangeAttribute Id="bdMarketingShortDescription" Type="string" Value="LW short" />
    </ChangeNode>
</NODES_OPERATIONS>

This statement works fine. However, I need to put HTML in the Value attribute, like this: need to send the following:

<?xml version="1.0" encoding="utf-8" ?>
<NODES_OPERATIONS>
    <ChangeNode URL="C294785" >
        <ChangeAttribute Id="bdMarketingShortDescription" Type="string" Value="<div>LW short</div>" />
    </ChangeNode>
</NODES_OPERATIONS>

but I have to HTML encode the Value, so it ends up looking like this:

<NODES_OPERATIONS>
    <ChangeNode URL="C294785" >
        <ChangeAttribute Id="bdMarketingShortDescription" Type="string" Value="&lt;div&gt;LW short&lt;/div&gt;" />
    </ChangeNode>
</NODES_OPERATIONS>

There could be one or many ChangeAttributes. I'm am building this using a string builder.

Any type of HTML, either encoded or not, throws an error that the XML can't be parsed. The third party service is written in Java and they don't know what the issue is. They DO support HTML in the value.

The only thing I can come up with here is that the .Net string is UTF 16, not UTF 8, but I'm not sure how to convert this as it works fine when Value is a simple string, but not when it's HTML encoded. Any ideas on what to do here?

mason
  • 31,774
  • 10
  • 77
  • 121
Craig
  • 11
  • 1
  • Use a tool such as Fiddler or WireShark to see what you're actually sending to the server. Since the server works when you input your data into the web interface, the problem is likely either with your code or some bug in the .NET framework. – mason Jan 26 '15 at 21:42
  • Have you tried using CDATA for the HTML? Also to simplify testing use SOAP UI to run tests. See this question http://stackoverflow.com/questions/1398571/html-inside-xml-should-i-use-cdata-or-encode-the-html – Namphibian Jan 26 '15 at 22:00
  • And their web service has utf 8? – Yuriy Zaletskyy Jan 26 '15 at 23:50

0 Answers0