views:

45

answers:

1

I have the following WCF service host console application:

static void Main(string[] args)
{
    ServiceHost serviceHost =
       new ServiceHost(typeof(MyServiceName<int>));
    serviceHost.Open();
    Console.ReadLine();
}

I tried to configure an endpoint for it:

<services>
  <service name="MyNamespace.MyServiceName&lt;int&gt;">
    <endpoint
      address="net.tcp://localhost:8002/MyServiceName"
      binding="netTcpBinding"
      contract="MyNamespace.IMyServiceName&lt;int&gt;"/>
  </service>
</services>

But it doesn't work. Is the &lt; and &gt; the problem?

+1  A: 

Your contract must be a concrete type - you cannot use generics in that, sorry.

WCF is a very different beast than straight-up .NET - and since a lot of stuff needs to be "reduced" to what XML schema can express, you cannot use interfaces (for the most part) and generics.

You'll have to create concrete interfaces and use those as service contracts.

marc_s
Contract can be an interface as well. The interface _can_ be a generic but as marc_s says, the implementation class can't be a generic.
MattC
@MattC: so the "Contract=" with the generic is OK? I'm amazed..... I'll have to try that some day :-)
marc_s
@marc_s: no no no. Sorry, I misunderstood your comment. I thought you were referring to the actual contract not the value in the web.config.
MattC