wcfrestvisual-studio-2010.net-4.0-beta-2

WCF - using multiple bindings including REST (WebHttpBinding) on one service library?


I want to expose my Service Layer (which is currently written as standard class library with POCOs) for external as well as internal consumption. External clients will use it over REST style APIs while internally my MVC app will use it over net.tcp binding for better performance.

How do I do this elegantly? I can write 2 wrappers one for REST using VS2010 Beta 2 REST features and other using standard WCF bindings.

Can I do this in one wrapper? or better just refactoring my existing services as WCF and expose on various endpoints using different bindings like WebHTTPBinding, WsHttpBinding, etc.

Regards,

Ajay


Solution

  • Your service library will only contain the implementation of the service - your service (and data) contracts should be in their own separate "Contracts" assembly.

    The question of hosting and what protocol to use is handled by your service host - this can be IIS or a separate NT Service or a console app or something. That is totally independant of your service class and your service library.

    So yes - you can easily create a service library and then expose that service over a multitude of endpoints in your service host - those two things should be kept totally separate from one another.