当我想在 WCF 中以复合类型发送 devExpress 会话时出现异常。我试图让它可序列化,但我仍然得到错误
信息:不应
System.Data.SqlClient.SqlConnection
包含数据合同名称SqlConnection:http://schemas.datacontract.org/2004/07/System.Data.SqlClient
的类型。DataContractResolver
如果您正在使用DataContractSerializer
或将任何静态未知的类型添加到已知类型列表中,请考虑使用 a - 例如,通过使用 KnownTypeAttribute 属性或将它们添加到传递给序列化程序的已知类型列表中。
这是我使用的 DataContract。
[DataContract]
[Serializable]
[ServiceKnownType(typeof(Session))]
[ServiceKnownType(typeof(SqlConnection))]
[ServiceKnownType(typeof(SqlParameter))]
public class CompositeType
{
Session sValue ;
[DataMember]
public Session SessionValue
{ get {return sValue; } set {sValue = value; } }
}
我还使用一种将此类作为参数发送的方法
void GetDataUsingDataContract(CompositeType composite);