代理类定义缺少FieldSpecified属性

时间:2015-11-16 10:32:36

标签: c# xml web-services soap xsd

我在.NET服务层中引用外部SOAP服务(通过外部我的意思是由另一个开发团队创建)作为服务引用。

我之前已经多次执行过这种类型的操作,通常生成的代理将包含一个带有数据字段的类结构,然后是<FieldName>FieldSpecified属性,以允许选择性地填充这些字段。

这种方法效果很好,因为它基本上将信息传递回另一个应用程序以更新其数据库中的某些字段。

以下是过去使用 生成所需行为的示例类:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.sampleproxyclass.com/updatecustomer")]
public partial class Customer : object, System.ComponentModel.INotifyPropertyChanged {


    private string CustomerName;

    private System.Nullable<System.DateTime> dateOfBirthField;

    private bool dateOfBirthFieldSpecified;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    public string CustomerName{
        get {
            return this.CustomerName;
        }
        set {
            this.CustomerName= value;
            this.RaisePropertyChanged("CustomerName");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(DataType="date", IsNullable=true, Order=4)]
    public System.Nullable<System.DateTime> dateOfBirth{
        get {
            return this.dateOfBirthField;
        }
        set {
            this.dateOfBirthField= value;
            this.RaisePropertyChanged("dateofBirth");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool dateOfBirthFieldSpecified{
        get {
            return this.dateOfBirthFieldSpecified;
        }
        set {
            this.dateOfBirthFieldSpecified= value;
            this.RaisePropertyChanged("dateOfBirthFieldSpecified");
        }
    }

}

出于某种原因,这个最新服务根本不会生成FieldSpecified属性,这会导致我们出现严重的集成问题。我无法控制XSD规范或创建,但我一直在努力帮助负责XSD的团队更改定义,以便在我的示例中生成如上所述的代理。

我认为关键是要将minOccurs="0"添加到定义中,但这没有用。我也让他们尝试nillable="true",但又没有快乐。

所以我的问题是当一个服务引用被添加到.NET项目时,XSD配置驱动创建FieldSpecified属性是什么?

我正在使用VS2013,Framework 4.5.1。

1 个答案:

答案 0 :(得分:0)

回答你的问题;根据MSDN,这种语法应该为您提供可为空的类型。

   <xs:element minOccurs="1" maxOccurs="1" name="NameNullable" nillable="true" type="xs:string" />

不幸的是,这从未如此直截了当。我最后编写了自己的工具来改变VS生成的代码。您可能还需要做类似的事情。

我刚刚对stackoverflow进行了类似问题的搜索,我找到了this。 有些人评论说,他们编写了自己的工具来处理这类问题。似乎没有简单的方法。

相关问题