0
  • IGenericService resides in the Assembly Named: "ABC.Server.Common" (ABC.Server.Common.dll)
  • MyType resides in the Assembly Named: "ABC.Server.Modules.X" (ABC.Server.Modules.X.dll)

CODE:

public class ABC.Server.Modules.XService :
    ABC.Server.Common.IGenericService<ABC.Server.Module.X.MyType>
{
    ABC.Server.Common.GenericResponse<ABC.Server.Module.X.MyType> DoFoo(ABC.Server.Common.GenericRequest<ABC.Server.Module.X.MyType> request)
    {
        //Do Stuff Here
    }
}

Condensed Code:

public class XService :
    IGenericService<MyType>
{
    GenericResponse<MyType> DoFoo(GenericRequest<MyType> request)
    {
        //Do Stuff Here
    }
}

Web.config:
I don't use SVC files, instead I have that information taken care of in the Web.config:

<add factory="System.ServiceModel.Activation.ServiceHostFactory"
     relativeAddress="Services/X.svc"
     service="ABC.Server.Modules.X.XService"/>

<service name="ABC.Server.Modules.X.XService"
         behaviorConfiguration="StandardBehavior">
  <endpoint bindingConfiguration="StandardBinding"
            binding="basicHttpBinding"
            contract="?" />
</service>

What do I put in the contract name to get it to actually work?

michael
  • 14,844
  • 28
  • 89
  • 177
  • See: http://stackoverflow.com/questions/6216858/generic-service-contract – marc_s Jun 23 '11 at 16:04
  • or: http://stackoverflow.com/questions/6223886/wcf-generic-service-interface – marc_s Jun 23 '11 at 16:05
  • 2
    Typically this not recommended - WCF cannot handle generics well, since it needs to be interoperable and must be able to express everything on the service contract in XML schema definitions - and XML schema doesn't do generics.... – marc_s Jun 23 '11 at 16:06
  • @marc_s: I thought that WCF _can_ handle generics well because it statically types things out: IGenericService becomes IGenericServiceOf_TypeT or something similar. – michael Jun 23 '11 at 16:42
  • You need to keep two things apart: (1) inside a WCF service it's pure .NET programming and you can use any of the .NET features you like (including generics etc.), but (2) outwards from WCF, you need to be interoperable, and as far as I know, a lot of languages and systems out there don't support generics - including the XML schema which is used to describe the services provided by WCF – marc_s Jun 23 '11 at 17:20
  • @michael: marc_s is correct. What you're thinking of is using Generics on your `DataContract` and `CollectionDataContract` ... you can use `{0} ... {N}` in the `Name` property of the attribute to place the type name. `[DataContract(Name = "Get{0}")] class GetGeneric` will yield a "Getint" or "GetFoo" or etc as the concrete type name. This does not work on `OperationContract` or `DataMember`. Why? I have no idea :) – myermian Jun 28 '11 at 19:40

1 Answers1

5

In general you can learn what WCF is expecting you to put for the ContractName with the following code snippet:

ContractDescription.GetContract(typeof(IGenericService<MyType>)).ConfigurationName
alexdej
  • 3,751
  • 23
  • 21