I am trying to integrate an application with a third party webservice. The signature of the method I have to call is something like this (generated by VS proxy generator):
string MyFoo(string param1, string param2, string param3, string someXml)
Now for the first 3 parameters there's no problem. The fourth parameter, as per vendor specifications, should contain "unescaped xml wrapped in a CDATA block", like this:
<![CDATA[<?xml version="1.0" encoding="utf-8"?><rootNode></rootNode>]]>
Now, c# escapes (as I would expect it to do) all the characters that must be escaped, mainly the "<" and ">" characters, even in the CDATA statement, resulting in something like this:
<![CDATA[<?xml version="1.0" encoding="utf-8"?><rootNode></rootNode>]]>
As far as I know this is a correct behaviour, and there's no way to override it, as it could potentially generate a bad request (invalid soap message) and even a security issue.
Does anyone know if I'm missing out on something, not knowing something, or this is correct and the expectation of the third party webservice cannot be complied?
Thanks.
I've been fiddling around the similar problem for > 2 days as of today. The only feasible solution that worked for me was to write service client (an interface and Client implementation) myself. This would be a problem if your service changes from time to time (you will not be able to regenerate/update your client with 3 clicks). Let me tell what I've done.
Simple and fast recipe:
XmlDocument doc = new XmlDocument();
var section = doc.CreateCDataSection(someXmlString);
string result = client.MyFoo(param1, param2, param3, section);
V. Kasparavičius is right. But it is much simple, this just needs a little change in Reference.cs
. The type of the parameter needs to be changed from string
to XmlCDataSection
.
private XmlCDataSection foo;
[System.Xml.Serialization.XmlElementAttribute(Order=2)]
public XmlCDataSection foo {
get {
return this.foo;
}
set {
this.foo = value;
this.RaisePropertyChanged("foo");
}
}
And then add the parameter as XmlCDataSection
var xmlDocument = new XmlDocument();
var parameter = xmlDocument.CreateCDataSection("<foo></foo>");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With