2011-01-12 16 views
0

次の問題があります。Visual Studio 2008 Web参照プロキシクラスでxml属性がデコードされない

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> 

私は参照を追加するには、Add Web参照を使用していました。 .NET 2.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サービスがデシリアライズされますとき、ある、商品コードとグループIDは、何らかの理由(彼らはnullに残されている)直列化復元されません。

答えて

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では、正しく私のテストスキーマファイルの属性が完全に修飾したことを認識し、あなたの生成されたコードは、スキーマを使用して期限切れのため、この問題は、(発生している可能性があるように思えるすなわちスキーマスキーマから元のコードを生成したときに属性が修飾されていない修飾された属性を使用するように更新されました)。

希望がある!

+0

あなたは最高です! Btw、修飾された属性名は何ですか?また、修飾されていない属性との違いは何ですか? – Bogi

+0

@Bogi修飾された属性には、名前空間接頭辞(例では "conc")が含まれます。指定した例は、修飾された属性を使用しています: ''各属性に先行する「conc:」は、属性を「修飾」にするものです。これらの属性が未修飾の場合、この要素は次のようになります。 '' – pmartin

関連する問題