我有一个发送
的 WebRequest 服务(外部客户端)<Sales>
<Customer>
<Name>John</Name>
</Customer>
<Goods>
<Good>
<id>5445</id>
</Good>
<Good>
<id>6767</id>
</Good>
</Goods>
</Sales>
但是当收到 XML 时,Goods 神秘地添加了一个 namespace 。
<Good xlmns="http://example.com/INT">
我的服务是:-
[OperationContract]
[WebInvoke(UriTemplate = "SendRequest", BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", ResponseFormat = WebMessageFormat.Xml)]
public Sales(clsCustomer Customer, clsGoods Goods)
我必须删除 Xlmns。
当 XML 被解析为函数的参数时,Customer 对象被填充,但 Goods 对象为空。当我在 Goods 和 Good 之间添加一个额外的节点层并使用 XMLElement 接受这些值时,我发现节点 Good 现在有一个我没有添加的 namespace 。在内部,Good 现在是 <Good xlmns="http://example/Int">
, 如何防止 .NET 添加 xmlns?
最佳答案
首先将Goods
转换为整数列表中的字符串列表:
Goodstr = Goods.ConvertAll(delegate(int i) { return i.ToString(); });
并使用它来填充 XML
关于c# - 命名空间被添加到 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28364614/