NetNamedPipeBinding:管道方法中的参数为空

时间:2011-06-30 19:16:09

标签: c# wcf servicehost netnamedpipebinding

我在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);
    }
}

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

[DataContract]
[KnownType(typeof(CitrixInfoServiceRequest))]   // added this line
[KnownType(typeof(RegStateServiceRequest))] // added this line
public abstract class ServiceRequestBase
{
    // ...
}