0

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);
    }
}
Trevor
  • 13,085
  • 13
  • 76
  • 99
  • Can you show us the code that call the PipeRequest please. – Jethro Jun 30 '11 at 19:20
  • Perhaps the service contract isn't properly handling inheritance. Or perhaps I'm not properly implementing inheritance. Can anyone confirm either of these hypotheses? – Trevor Jun 30 '11 at 20:11
  • The `KnownType` attribute is a correct way to implement inheritance; if you'd set that up incorrectly you'd get an exception. When you say the parameter is 'empty' - is it null, or does it have properties which don't have the values you expect? – Steve Wilkes Jun 30 '11 at 20:34
  • Strings are simply "" empty. Enums are 0 even though the only possibilities are { EnumVal1 = 1, EnumVal2 = 2 }. Strange. – Trevor Jun 30 '11 at 20:42

2 Answers2

1

It look like it has to do with proxy.PipeRequest(this); You need to pass in a class that inherits ServiceRequestBase, if you class does inherit the ServiceRequestBase then it might not be serializable.

Jethro
  • 5,896
  • 3
  • 23
  • 24
  • The Dispatch() method is actually in the ServiceRequestBase class. I'll correct that in my post. – Trevor Jun 30 '11 at 20:38
0

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
{
    // ...
}
Trevor
  • 13,085
  • 13
  • 76
  • 99