【问题标题】:Proxy class definition missing FieldSpecified properties代理类定义缺少 FieldSpecified 属性
【发布时间】:2015-11-16 19:26:10
【问题描述】:

我在我的 .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,框架 4.5.1。

【问题讨论】:

  • 你用什么来生成这些类?
  • @KosalaW 只是标准的 VS IDE 生成器 - 通过向我的项目添加新的服务引用。
  • 我过去曾遇到过这种情况。据我所知,这就是我所做的。我让他们把xsd寄给我。然后我使用 xsd2code 生成我的参考类。使用这些参考资料,我托管了自己的 wcf 服务。然后我使用我的 wcf 服务创建了一个客户端。我多次摆弄 xsd,直到它给了我想要的客户端。

标签: c# xml web-services soap xsd


【解决方案1】:

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

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

不幸的是,这从来都不是直截了当的。过去,我最终编写了自己的工具来更改 VS 生成的代码。您可能还需要做类似的事情。

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

【讨论】:

  • 感谢您的信息,我们仍在努力解决此问题,所以当我有一些信息时,我会发布更多信息。
猜你喜欢
  • 1970-01-01
  • 2016-03-19
  • 1970-01-01
  • 2021-05-28
  • 1970-01-01
  • 2021-12-20
  • 2014-05-24
  • 1970-01-01
  • 2019-03-04
相关资源
最近更新 更多