Search code examples
c#wcfservicehostnetnamedpipebinding

NetNamedPipeBinding: parameter in pipe method is empty


I have a ServiceHost listening on a NetNamedPipeBinding endpoint. I have a service contract class with a single method which is being called by the client and handled by the server. The method (We'll call it PipeRequest()) has a Request parameter. On the client side I populate this object but it's empty by the time it gets sent over to the server. Any ideas why this would be the case?

_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);
    }
}

Solution

  • It turns out I had to specify (as part of the data contract) any derived classes from ServiceRequestBase class.

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