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><![CDATA[<Info><Test><ID>1</ID><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.
IXmlSerializable? It allows you to control the formatting."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".<![CDATA[<Info><Test><ID>1</ID><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.