C# VisualStudio2008 web引用代理类没有';不解码xml属性

C# VisualStudio2008 web引用代理类没有';不解码xml属性,c#,.net,web-services,proxy-classes,xml-attribute,C#,.net,Web Services,Proxy Classes,Xml Attribute,我有一个问题: 我正在编写用于使用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

我有一个问题:

我正在编写用于使用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>
HTTP/1.0 200正常
内容类型:text/xml;字符集=utf-8
连接:关闭
以下是.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;
        }
    }
}
//
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“2.0.50727.4927”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://tempuri.org/XMLSchema.xsd")]
公共部分类GetProductsResponse{
私有GetProductsResponseResult结果字段;
/// 
公共获取产品响应结果{
得到{
返回此.resultField;
}
设置{
this.resultField=值;
}
}
}
/// 
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“2.0.50727.4927”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://tempuri.org/XMLSchema.xsd")]
公共部分类GetProductsResponseResult{
私人产品私人产品领域;
/// 
公共产品私人产品{
得到{
返回此.products字段;
}
设置{
this.productsField=值;
}
}
}
/// 
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“2.0.50727.4927”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(命名空间=”http://tempuri.org/XMLSchema.xsd")]
公共部分类ProductsType{
private ProductsTypeProduct[]项目字段;
/// 
[System.Xml.Serialization.xmlementAttribute(“产品”)]
公共产品产品[]项{
得到{
返回此.itemsField;
}
设置{
this.itemsField=值;
}
}
}
/// 
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“2.0.50727.4927”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://tempuri.org/XMLSchema.xsd")]
公共部分类ProductsTypeProduct{
私有字符串productIDField;
私有字符串groupIDField;
/// 
[System.Xml.Serialization.XmlAttributeAttribute()]
公共字符串ProductID{
得到{
返回此.productIDField;
}
设置{
this.productIDField=值;
}
}
/// 
[System.Xml.Serialization.XmlAttributeAttribute()]
公共字符串组ID{
得到{
返回此.groupIDField;
}
设置{
this.groupIDField=值;
}
}
}

问题是,当web服务被反序列化时,ProductID和GroupID由于某种原因没有被反序列化(它们被保留为null)。

我第一次很接近,但这实际上与我最初认为的问题有点不同

问题是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;
        }
    }
//
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified”)]
公共字符串ProductID{
得到{
返回此.productIDField;
}
设置{
this.productIDField=值;
}
}
/// 
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified”)]
公共字符串组ID{
得到{
返回此.groupIDField;
}
设置{
this.groupIDField=值;
}
}
XSD.exe正确地识别出我的测试架构文件中的属性是完全限定的,因此似乎出现了此问题,因为生成的代码与架构过时(即,模式已更新为现在使用限定属性,而当您最初从模式生成代码时,属性未限定)


希望这会有帮助!!!

你是最好的!!!顺便问一下,什么是限定属性名,与非限定属性有什么区别?@Bogi限定属性包括名称空间前缀(在您的示例中是“conc”)。您提供的示例使用限定属性:
。“conc:”在每个属性前面是使属性“合格”的原因。如果这些属性是不合格的,则该元素将如下所示