我使用标准的wsdl (位于这里)与服务(OpenXDS)通信。我从它创建了一个服务引用,它生成了一个非常大的Reference.cs文件。文件中有如下类型的层次结构:
public partial class ExtrinsicObjectType : RegistryObjectType。。。
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ExtrinsicObjectType))]
public partial class RegistryObjectType : IdentifiableType。。。
[System.Xml.Serialization.XmlIncludeAttribute(typeof(RegistryObjectType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ExtrinsicObjectType))]
public partial class IdentifiableType : object这三种类型都具有相同的XmlType:
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")]IdentifiableType对象的响应类型中有一个集合:
[System.Xml.Serialization.XmlArrayAttribute(Namespace="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("Identifiable", IsNullable=false)]
public IdentifiableType[] RegistryObjectList { 当服务实际响应时,它提供了一个ExtrinsicObject元素的集合:
<rim:RegistryObjectList xmlns:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0">
<ns1:ExtrinsicObject xmlns:ns1="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" ...
<ns1:ExtrinsicObject xmlns:ns1="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" ...
<ns1:ExtrinsicObject xmlns:ns1="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" ...
<ns1:ExtrinsicObject xmlns:ns1="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" ...
<ns1:ExtrinsicObject xmlns:ns1="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" ...
</rim:RegistryObjectList>我在跟踪日志中看到了这些元素,我可以在SoapUI中得到相同的答案。但是当我从客户机代理获得反序列化响应时,RegistryObjectList是空的。它完全忽略了ExtrinsicObject元素。
我无法更改服务器,客户端由VS2012生成。看上去这应该能起作用,但我错过了一些环境什么的。
以下是我到目前为止的理论:
任何帮助都是非常感谢的。我试图包含我认为相关的内容,但是由于wsdl、xsd和Reference.cs都相当大,所以进行了大量的编辑。
发布于 2016-12-14 22:10:37
通过将以下XmlAttributeOverrides传递给序列化程序,我就完成了这个任务:
var overrides = new XmlAttributeOverrides();
overrides.Add(typeof(SubmitObjectsRequest), "RegistryObjectList", new XmlAttributes
{
XmlArray = new XmlArrayAttribute()
{
Namespace = "urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0",
Order = 0
},
XmlArrayItems =
{
new XmlArrayItemAttribute("ExtrinsicObject", typeof(ExtrinsicObjectType)) { IsNullable = false },
new XmlArrayItemAttribute("RegistryPackage", typeof(RegistryPackageType)) { IsNullable = false }
}
});据我所知,正如您所说的,Reference.cs给出了以下内容:
[System.Xml.Serialization.XmlArrayAttribute(Namespace="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("Identifiable", IsNullable=false)]
public IdentifiableType[] RegistryObjectList {但是,由于在XML中,RegistryObjectList元素没有Identifiable子节点,而是有ExtrinsicObject和RegistryPackage子节点,所以我真正希望它看起来如下所示:
[System.Xml.Serialization.XmlArrayAttribute(Namespace="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", Order=0)]
[System.Xml.Serialization.XmlArrayItemAttribute("ExtrinsicObject", typeof(ExtrinsicObjectType), IsNullable=false)]
[System.Xml.Serialization.XmlArrayItemAttribute("RegistryPackage", typeof(RegistryPackageType), IsNullable=false)]
public IdentifiableType[] RegistryObjectList {并且,包含重写将使序列化程序忽略原始属性,并将RegistryObjectList视为已用后者修饰过的东西。
https://stackoverflow.com/questions/18618920
复制相似问题