Interoperable way to send XML data in WCF?

岁酱吖の 提交于 2019-12-11 17:52:27

问题


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 &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.



来源:https://stackoverflow.com/questions/3505446/interoperable-way-to-send-xml-data-in-wcf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!