WCF中继承DataContract
我有一个名为 Credentials
的 DataContract
,我已将其继承到我自己的名为 MyCredentials
的业务对象中并进行了自定义。我想通过网络发送它,但可以理解的是我收到了错误。
尝试序列化参数时出错
有没有办法在不进行业务对象和 DataContracts 之间转换的情况下解决此问题?我的代码工作看起来像这样
[DataContract]
[KnownType(typeof(Credentials))]
internal class MyCredentials : Credentials
{
public MyCredentials ()
{
}
}
I have a DataContract
say called Credentials
which I've inherited into my own business object called MyCredentials
and customized. I want to send it over the wire but understandably I get an error.
There was an error while trying to serialize parameter
Is there a way to resolve this without doing a conversion between business object and DataContracts
? My code work looks something like this
[DataContract]
[KnownType(typeof(Credentials))]
internal class MyCredentials : Credentials
{
public MyCredentials ()
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用 KnownType-Attribute 来修饰基类 Credentials。
另外,我认为当您使用 DataContractAttribute 装饰该类时,需要将其设为公共类而不是内部类。
You need to decorate the base class Credientials with the KnownType-Attribute.
Also i think you need to make the class public and not internal when you decorate it with the DataContractAttribute.
毕竟它是一个契约,可访问性修饰符不会影响 DataContract。
Accessibility modifiers do not affect a DataContract after all it is a contract.