Asp.net WCF&;亚音速类-反序列化器没有任何类型的知识映射到此合同
我的WCF客户端出现以下错误:Asp.net WCF&;亚音速类-反序列化器没有任何类型的知识映射到此合同,asp.net,wcf,subsonic,wcf-binding,Asp.net,Wcf,Subsonic,Wcf Binding,我的WCF客户端出现以下错误: "Error in line 1 position 1910. Element 'http://schemas.datacontract.org/2004/07/SubSonic:_currentValue' contains data of the 'http://schemas.datacontract.org/2004/07/System:DBNull' data contract. The deserializer has no knowledge of
"Error in line 1 position 1910. Element 'http://schemas.datacontract.org/2004/07/SubSonic:_currentValue' contains data of the 'http://schemas.datacontract.org/2004/07/System:DBNull' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'DBNull' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer."
我正在使用亚音速2.0生成我的类对象
我还使用DataContract
和DataMember
装饰了我的类和成员
已尝试将[KnownType(typeof(System.DBNull))]
添加到生成的类中
已尝试将[ServiceKnownType(typeof(System.DBNull))]
添加到我的服务界面
我生成的类如下所示:(该类是为SQL视图生成的)
所以,当反序列化客户端未获得System.DBNull类型时。我们必须在客户端配置文件中添加knowntypes
客户端需要此配置,解决了我的问题:
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="NameSpace.ServiceClientName.ClassNameForWhichKnownTypeIsToBeGiven, AssemblyName">
<knownType type="System.DBNull"></knownType>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>
希望这将是有用的人
[ServiceContract]
[ServiceKnownType(typeof(System.DBNull))]
public interface IPatientService
{
[WebInvoke(Method = "GET", UriTemplate = "GetPatientAppointments")]
[OperationContract]
IList<VwPatientRt> GetPatientAppointments();
.....
public class PatientService : IPatientService
{
public IList<VwPatientRt> GetPatientAppointments()
{
... .
.....
}
...
[ServiceKnownType(typeof(System.DBNull))]
<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="NameSpace.ServiceClientName.ClassNameForWhichKnownTypeIsToBeGiven, AssemblyName">
<knownType type="System.DBNull"></knownType>
</add>
</declaredTypes>
</dataContractSerializer>
</system.runtime.serialization>