我有一个具有 2 个端点的 Java Web 服务器:SystemManagement 和 UserManagement。2 个端点使用相同的库。因此,这两个端点中的几乎所有类都是相同的。
我有一个使用这 2 个服务的 C# 客户端。我知道 WCF 可以共享课程。所以我做了一个新项目,让我的客户项目引用这个新项目。然后在新项目中创建一个通用类“会话”。
namespace WcfExplore.UserManagement
{
[DataContract]
public partial class session : object, System.ComponentModel.INotifyPropertyChanged
{
private string sessionIdField;
private string useridField;
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 3)]
[DataMember]
public string sessionId
{
get { return this.sessionIdField; }
set
{
this.sessionIdField = value;
this.RaisePropertyChanged("sessionId");
}
}
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 4)]
[DataMember]
public string userid
{
get { return this.useridField; }
set
{
this.useridField = value;
this.RaisePropertyChanged("userid");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if (propertyChanged != null)
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
但是当我更新服务引用时,Visual Studio 仍然会自己生成“会话”类。
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://iboss2.service.iasia.com/")]
public partial class session : object, System.ComponentModel.INotifyPropertyChanged {
private string sessionIdField;
private string useridField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
public string sessionId {
get {
return this.sessionIdField;
}
set {
this.sessionIdField = value;
this.RaisePropertyChanged("sessionId");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=4)]
public string userid {
get {
return this.useridField;
}
set {
this.useridField = value;
this.RaisePropertyChanged("userid");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
如何使 2 个服务引用使用公共类?我不希望 2 个服务引用生成自己的重复类。