views:

276

answers:

3

Hi,

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

A: 

Sure you can just add more of them to the configuration file or using the code.

Dani
+1  A: 

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.

marc_s
"That is totally independant of your service class and your service library." in practice this is not necessarily the whole story. E.g. if you want to expose a service through two different SVC files. This will require you to provide dedicated implementations even if those are just derived implementations from a shared one. There is just no way to reference a service config without it. Would you agree?
Alex
@Alex: agreed, but that seems like a bit of an edge case to me. Why would you ever want to expose the same service through two separate *.svc files? Plus: anything in production, I'd self-host anyway....
marc_s
I needed this in a couple of IIS hosted services consumed by clients implemented on various different technology stack (PHP, Java, .NET).
Alex
A: 

VS 2010 Beta 2's REST features are themselves built on top of WCF, so if you want to use them you'll have to refactor your service into a WCF service anyway. At that point, as Dani and marc_s say, you can very easily add additional endpoints to the service through the configuration file.

Aaron