在项目中用到WCF,项目的结构是这样的:

在SPI项目中编写该解决方案中公共的类及函数;
在WCFService项目中写的是svc文件及WCF服务接口;
在Client中添加WCF服务引用的时候该WCFService项目,然后再UI项目中初始化Client的实例。通过该实例WCFService中的方法。
问题:
有时会出现这么一种情况,在UI中通过初始化Client的实例。通过该实例WCFService中的方法MethodA,该方法的入参是SPI中类ConnectionInfo的实例,,然后在UI中再次使用类ConnectionInfo时会发现ConnectionInfo是在Client命名空间下的类,而不是在SPI命名空间下的类。
在WCF自动生成的客户端代理类(Reference.cs文件)中,会将SPI中的类ConnectionInfo,序列化成:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="ConnectionInfo", Namespace="" +
"el")]
[System.SerializableAttribute()]
public partial class ConnectionInfo : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string ConnectionStringField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string GuidField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string LocationField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string MenuGuidField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string NameField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string TypeField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private int idField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string ConnectionString {
get {
return this.ConnectionStringField;
}
set {
if ((object.ReferenceEquals(this.ConnectionStringField, value) != true)) {
this.ConnectionStringField = value;
this.RaisePropertyChanged("ConnectionString");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Guid {
get {
return this.GuidField;
}
set {
if ((object.ReferenceEquals(this.GuidField, value) != true)) {
this.GuidField = value;
this.RaisePropertyChanged("Guid");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Location {
get {
return this.LocationField;
}
set {
if ((object.ReferenceEquals(this.LocationField, value) != true)) {
this.LocationField = value;
this.RaisePropertyChanged("Location");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string MenuGuid {
get {
return this.MenuGuidField;
}
set {
if ((object.ReferenceEquals(this.MenuGuidField, value) != true)) {
this.MenuGuidField = value;
this.RaisePropertyChanged("MenuGuid");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Name {
get {
return this.NameField;
}
set {
if ((object.ReferenceEquals(this.NameField, value) != true)) {
this.NameField = value;
this.RaisePropertyChanged("Name");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Type {
get {
return this.TypeField;
}
set {
if ((object.ReferenceEquals(this.TypeField, value) != true)) {
this.TypeField = value;
this.RaisePropertyChanged("Type");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public int id {
get {
return this.idField;
}
set {
if ((this.idField.Equals(value) != true)) {
this.idField = value;
this.RaisePropertyChanged("id");
}
}
}
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));
}
}
}
该实体类代码为:/// <summary>
/// 数据源信息
/// </summary>
public class ConnectionInfo
{
public int id { get; set; }
public string Guid { get; set; }
public string Name { get; set; }
public string Location { get; set; }
public string Type { get; set; }
public string ConnectionString { get; set; }
public string MenuGuid { get; set; }
}
在 CLient项目的wcf引用上右键,可以看到该实体类