【发布时间】: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