我是WCF
的新手,面临一些问题。我有三个项目WCFClient
,WCFService
,CommonModel
CommonModel
: - 有以下课程
public class Room: INotifyPropertyChanged
{
int roomID;
public virtual int roomID_PK { get; set; }
public Room()
{
Row1Details = new RoomRowDetails();
Row2Details = new RoomRowDetails();
}
}
[Serializable]
public class RoomRowDetails : ISerializable, INotifyPropertyChanged
{
public RoomRowDetails()
{
RoomColor = "White";
RowSaleAmount = "";
}
....
}
WCFClient
:正在使用客户端代理类。 WCFService
:ServiceContract
OperationContract
DataContract
并且有以下课程: -
[DataContract()]
[ServiceKnownType(typeof(Room))]
[ServiceKnownType(typeof(RoomRowDetails))]
public class RequestData
{
[DataMember]
public string ClientName { get; set; }
[DataMember]
public bool isServer { get; set; }
[DataMember]
public bool isSuccess { get; set; }
[DataMember]
public Room room { get; set; }
[DataMember]
public RoomRowDetails roomrow{ get; set; }
}
在项目中添加CommandModel
项目作为参考。客户端代理生成正确但在运行项目时。我得到以下错误: -
There was an error while trying to serialize parameter http://tempuri.org/:eventData. The InnerException message was 'Type 'CommonModel.MODELS.Room' with data contract name 'Room:http://schemas.datacontract.org/2004/07/CommonModel.MODELS' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.
您能帮我解决一下如何在CommonModel
服务和客户端中使用WCF
课程(So Room是项目之间的共享POCO)并避免上述错误吗?
谢谢