0

次の問題があります。

Webサービスを利用するためのクライアントコードを書いています。Webサービスからの回答は次のとおりです。

HTTP/1.0 200 OK
Content-Type: text/xml; charset=utf-8
Connection: close

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <conc:GetProductsListResponse xmlns:conc="http://tempuri.org/XMLSchema.xsd">
      <conc:Result>
        <conc:Products>
           <conc:Product conc:ProductID="4C475A0126111982" conc:GroupID="Default" />
        </conc:Products>
      </conc:Result>
    </conc:GetProductsListResponse>
  </soap:Body>
 </soap:Envelope>

これで機能する.xsdファイルと.wsdlファイルからの定義は次のとおりです。

  <xs:element name="GetProductsListResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Result">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Products" type="ProductsType" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="ProductsType">
    <xs:choice>
      <xs:element name="Product" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="ProductID" type="xs:string"/>
          <xs:attribute name="GroupID" type="xs:string"/>
        </xs:complexType>
      </xs:element>
      <xs:element name="Error">
        <xs:complexType>
          <xs:attribute name="ErrorID" type="xs:string"/>
        </xs:complexType>
      </xs:element>
    </xs:choice>
  </xs:complexType>

[Web参照の追加]を使用して参照を追加しました。.NET2.0スタイルのWebサービスを使用しました。

生成されたプロキシクラスは次のとおりです。

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/XMLSchema.xsd")]
public partial class GetProductsListResponse {

    private GetProductsListResponseResult resultField;

    /// <remarks/>
    public GetProductsListResponseResult Result {
        get {
            return this.resultField;
        }
        set {
            this.resultField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/XMLSchema.xsd")]
public partial class GetProductsListResponseResult {

    private ProductsType productsField;

    /// <remarks/>
    public ProductsType Products {
        get {
            return this.productsField;
        }
        set {
            this.productsField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/XMLSchema.xsd")]
public partial class ProductsType {

    private ProductsTypeProduct[] itemsField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("Product")]
    public ProductsTypeProduct[] Items {
        get {
            return this.itemsField;
        }
        set {
            this.itemsField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4927")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/XMLSchema.xsd")]
public partial class ProductsTypeProduct {

    private string productIDField;

    private string groupIDField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string ProductID {
        get {
            return this.productIDField;
        }
        set {
            this.productIDField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string GroupID {
        get {
            return this.groupIDField;
        }
        set {
            this.groupIDField = value;
        }
    }
}

問題は、Webサービスが逆シリアル化されたときに、ProductIDとGroupIDが何らかの理由で逆シリアル化されない(nullのままになる)ことです。

4

1 に答える 1

1

初めて近づいたのですが、実は思っていたより少し違う問題です。

問題は、Webサービス応答の属性が名前空間プレフィックスで修飾されているが、生成されたコードは属性が修飾されていることを識別していることです。次のコードを更新してSystem.Xml.Schema.XmlSchemaForm.Qualified、属性にパラメーターを追加すると、応答を受け取ったときにそれらのオブジェクトの入力が開始されます。

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified")]
    public string ProductID {
        get {
            return this.productIDField;
        }
        set {
            this.productIDField = value;
        }
    }
    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified")]
    public string GroupID {
        get {
            return this.groupIDField;
        }
        set {
            this.groupIDField = value;
        }
    }

XSD.exeは、テストスキーマファイルの属性が完全に修飾されていることを正しく認識したため、生成されたコードがスキーマと古くなっている(つまり、修飾されたコードを使用するようにスキーマが更新されている)ため、この問題が発生した可能性がありますスキーマからコードを最初に生成したときに属性が修飾されていなかった属性)。

お役に立てば幸いです!!!

于 2011-01-12T15:57:44.210 に答える