0

I'm using WCF Core Client in .NET 8.0 project so its generating the client from WCF service. There is a call that has a string value where the server is expecting a XML data enclosed in CDATA. e.g.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:gxw="http://schemas.datacontract.org/2004/07/GXWCF2">    
 <soapenv:Header/>    
 <soapenv:Body>       
  <tem:UpdateRecord>          
   <tem:nSomeID>101</tem:nSomeID>          
   <tem:strXML><![CDATA[<Info><Test><ID>1</ID><Message>Hello</Message></Test></Info>]]></tem:strXML>                
  </tem:UpdateRecord>    
 </soapenv:Body> 
</soapenv:Envelope>

So its the strXML is the issue, the auto-generated model has the field as string:

[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/")]
public string strXML;

But when this is sent the html raw data has the xml all escaped. <strXML>&lt;![CDATA[&lt;Info&gt;&lt;Test&gt;&lt;ID&gt;1&lt;/ID&gt;&lt;Message...

Whereas from SoapUI tests it isn't and server accepts it fine.

I've spent a while trying to figure out ways to get this to work and going around in a few circles with ChatGPT.

  • Tried to replace string in the model with XmlElement but its either ignored or get serialation exceptions.
  • Tried XmlCDataSection intead of string and also not supported/didn't work.
  • Another idea from AI was use "WCF Message Inspector to rewrite the raw SOAP body before it's sent", but again not supported by .NET 8.0.

In the end the only way was to use HttpClient and send the raw soap data myself. While this works there must be a way to do it within the WCF Core Client models which would be cleaner.

4
  • Did you have a look at IXmlSerializable? It allows you to control the formatting. Commented May 7 at 17:06
  • Could you please share a minimal reproducible example showing your service & operations contracts as well as your current types? E.g. "http://schemas.xmlsoap.org/soap/envelope/" is from Soap 1.1 but I'm not sure how you specify that, I'm used to seeing the Soap 1.2 namespace "http://www.w3.org/2003/05/soap-envelope". Commented May 8 at 18:09
  • By the way, &lt;![CDATA[&lt;Info&gt;&lt;Test&gt;&lt;ID&gt;1&lt;/ID&gt;&lt;Message... is actually semantically identical to <![CDATA[<Info><Test><ID>1</ID><Message>Hello</Message></Test></Info>]]. The only difference is the escaping style. So you could just accept it as-is. Commented May 8 at 18:47
  • Also, can you modify the service at all, or only the client code? Commented May 9 at 13:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.