问题
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!
回答1:
You are not sending XML as a string. You are sending XML. XML as a string means encoded (like <element/>) 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.
来源:https://stackoverflow.com/questions/3505446/interoperable-way-to-send-xml-data-in-wcf