WCF 服务序列化:反序列化器不知道映射到此名称的任何类型 [英] WCF Service Serialization: The deserializer has no knowledge of any type that maps to this name
问题描述
我正在尝试构建 WCF 服务,但遇到了阻塞问题.我一直在谷歌搜索,但我一直无法取得任何进展.希望我在这里能有更多的好运.
I'm trying to build out a WCF service but I've run into a blocking issue. I've been Googling around but I haven't been able to make any progress. Hopefully I'll have more luck here.
假设我有一个这样定义的工作类别:
Let's say I have a job class defined as such:
[DataContract]
public class Job : IJob
{
public Job(...)
{
}
[DataMember]
public string Example
{
get { return m_example; }
set { m_example = value; }
}
}
现在,我做的是这样的
public void DoSomething()
{
ExampleServiceProxy.ExampleClient proxy = new ExampleServiceProxy.ExampleClient();
proxy.DoSomething(job);
}
在我的 Reference.cs 中,我添加了一些 ServiceKnownTypeAttribute,如下所示:
Inside of my Reference.cs I've added some ServiceKnownTypeAttribute as follows:
...
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(Job))]
void DoSomething(object job);
我的服务代码如下:
[ServiceContract]
public interface IExample
{
[OperationContract]
void DoSomething(IJob);
}
public class Example : IExample
{
public void DoSomething(IJob job)
{
...
}
}
我需要在某处放置更多的 ServiceKnownTypeAttributes 吗?我需要在服务端重新实现对象吗?
Do I need to put further ServiceKnownTypeAttributes somewhere? Do I need to reimplement the object on the service side?
推荐答案
您必须将 ServiceKnownType 属性放在 Service Contract 接口上.
You have to put the ServiceKnownType attribute on the Service Contract interface.
[ServiceContract]
public interface IExample
{
[OperationContract]
[ServiceKnownType(typeof(Job))]
void DoSomething(IJob);
}
public class Example : IExample
{
public void DoSomething(IJob job)
{
...
}
}
这篇关于WCF 服务序列化:反序列化器不知道映射到此名称的任何类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!