在WCF中发送XML数据的互操作方式? [英] Interoperable way to send XML data in WCF?

查看:201
本文介绍了在WCF中发送XML数据的互操作方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用System.Xml.XmlElement作为在WCF中发送XML数据的参数.这通常是在WCF中发送XML数据的一种可互操作的方式,例如,如果我从WCF客户端发送数据,则PHP或Java Web Service将理解它?我读过我永远不要在WCF中直接将XML作为字符串发送.

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.

在WCF生成的WSDL中,XmlElement对象通过以下方式映射到xsd:any元素:

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>

xsd可以进行互操作吗?

Can xsd:any do the job for interoperability?

谢谢!

推荐答案

您没有将XML作为字符串发送.您正在发送XML. XML作为字符串表示经过编码(例如& lt; element/& gt;)的XML,其中XSD定义了string类型的单个元素.您应该始终尝试定义服务可以接受的XML,以便消息定义成为服务描述的一部分.如果您接受任何XML,则可以使用xsd:any或编码的XML作为参数,但始终检查传入的XML是否存在附加内容,并限制传入消息的大小,从而避免DoS攻击.

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.

这篇关于在WCF中发送XML数据的互操作方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆