views:

43

answers:

1

Hi,

I'm using System.Xml.XmlElement as a parameter for sending XML data in WCF. Is this generally the interoperable way to send XML data in WCF, so that, for example, a PHP or Java Web Service will understand it if I'll send it from a WCF Client? I've read that I should never send XML directly as string in WCF.

In WSDL generated by WCF the XmlElement object is mapped to the xsd:any element in the following way:

<xsd:element name="SendXMLData">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="MyXMLParameter" nillable="true">
<xsd:complexType>
<xsd:sequence>
<xsd:any minOccurs="0" processContents="lax" /> 
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

Can xsd:any do the job for interoperability?

Thanks!

A: 

You are not sending XML as a string. You are sending XML. XML as a string means encoded (like &lt;element/&gt;) XML where your XSD defines single element of type string. You should always try to define XML which is accepted by your service so that message definition is part of service description. If you accept any XML you can use xsd:any or encoded XML as paramter but always check incomming XML for possible attak and limit the size of incomming message so that you avoid DoS attack.

Ladislav Mrnka
An encoded XML string is indeed another useful way to send XML data in web services (via xsd:string). By using an encoded XML string I managed to send XML to a web service which didn't support xsd:any. It's also handy that in .NET you can get the encoded string automatically via XmlElement.OuterXml.