3

サービス (OpenXDS) と通信するために、標準の wsdl (ここにあります) を使用しています。そこからサービス参照を作成したところ、非常に大きな 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

3 つの型はすべて同じ XmlType を持ちます。

[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0")]

IdentifiableType オブジェクトの Response タイプにはコレクションがあります。

[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 は、彼らが同意した wsdl とは異なります。
  • 応答を手動で逆シリアル化する方法を理解する必要があります。

どんな助けでも大歓迎です。適切だと思われるものを含めようとしましたが、wsdl、xsd、および Reference.cs はすべてかなり大きいため、多くの編集が行われました。

4

1 に答える 1

0

次の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むしろ子ノードがあるため、私が本当に望んでいるのは、次のようにすることです。ExtrinsicObjectRegistryPackage

[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し、後者で装飾されているかのように扱います。

于 2016-12-14T22:10:37.597 に答える