【发布时间】:2010-11-23 15:45:05
【问题描述】:
我在向网络服务发送肥皂请求时遇到问题。我创建了一个订单,包括一系列订单详细信息。然后我将该订单发送到网络服务。使用提琴手,我可以看到订单正确传递,但订单详细信息未显示。我只得到:
<order><orderDetails><orderDetail /></orderDetails><order>
我尝试将 orderDetails 从订单详细信息数组更改为字符串数组,它们在请求中正确显示。我也得到了正确的订单数量。它们只是空的。
这两个类都是从 wsdl 生成的,所以我不知道为什么 orderDetail 似乎没有正确序列化。我不知道如何获取更多错误详细信息。任何帮助将不胜感激。谢谢
来自我的 Reference.cs,由我的 Web 服务生成:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://some.url")]
public partial class order {
private orderDetail[] orderDetailsField;
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("orderDetails", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public orderDetail[] orderDetails {
get {
return this.orderDetailsField;
}
set {
this.orderDetailsField = value;
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://some.url")]
public partial class orderDetail {
private int productIDField;
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public int productID {
get {
return this.productIDField;
}
set {
this.productIDField = value;
}
}
}
【问题讨论】:
-
对不起,经过进一步研究,这个问题可能会更简单。基本上我可以序列化订单对象,但序列化 orderDetails 对象只会返回一个空对象。它们似乎以相同的方式声明,所以我想知道是否有人知道为什么会发生这种情况或我如何调试序列化过程。
-
现在调试序列化,感谢这个页面platinumdogs.wordpress.com/2008/02/25/…
-
我可能是错的,但是您是否尝试过将 XmlArrayItemAttribute("orderDetails", 更改为 XmlArrayItemAttribute("orderDetail", ?
-
你是如何反序列化的?这几乎可以肯定是一个命名空间问题:您使用一个命名空间发送,但接收者期待另一个命名空间。
-
XmlArrayItemAttribute("orderDetails") 只是控制xml中使用的名称。更改它没有任何效果。
标签: c# serialization soap