0

我有一个在 NetNamedPipeBinding 端点上侦听的 ServiceHost。我有一个服务合同类,它有一个方法,由客户端调用并由服务器处理。该方法(我们称之为 PipeRequest())有一个 Request 参数。在客户端,我填充了这个对象,但是当它被发送到服务器时它是空的。任何想法为什么会这样?

_Host = new ServiceHost(typeof(PipeService), new Uri(ServiceRequestRouter.URI));
_Host.AddServiceEndpoint(
    typeof(IPipeService),
    new NetNamedPipeBinding(),
    _PipeName
);
_Host.Open();

[ServiceContract(Namespace = "http://www.example.com/PipeCommunication")]
interface IPipeService
{
    [OperationContract]
    void PipeRequest(ServiceRequestBase request);
}

[DataContract]
[KnownType(typeof(DerivedServiceRequest))]
[KnownType(typeof(SomeEnumType))]
public abstract class ServiceRequestBase
{
    ...

    public void Dispatch(string pPipeName = ServiceRequestRouter.DefaultPipeName)
    {
        EndpointAddress epa = new EndpointAddress(_address_));
        IPipeService proxy = ChannelFactory<IPipeService>.CreateChannel(new NetNamedPipeBinding(), epa);
        proxy.PipeRequest(this);
    }
}
4

2 回答 2

1

看起来它与proxy.PipeRequest(this); 您需要传入一个继承 ServiceRequestBase 的类有关,如果您的类确实继承了 ServiceRequestBase,那么它可能无法序列化。

于 2011-06-30T20:33:19.850 回答
0

事实证明,我必须指定(作为数据契约的一部分)来自 ServiceRequestBase 类的任何派生类。

[DataContract]
[KnownType(typeof(CitrixInfoServiceRequest))]   // added this line
[KnownType(typeof(RegStateServiceRequest))] // added this line
public abstract class ServiceRequestBase
{
    // ...
}
于 2011-08-05T17:43:55.087 回答