Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF Service in Separate Assembly

Tags:

c#

.net

wcf

What is the correct way to create a WCF service in separate assembly but then expose its endpoint through a Web Project in the same solution?

like image 256
BuddyJoe Avatar asked Jun 18 '10 16:06

BuddyJoe


1 Answers

I've done it this way:

  • Build your WCF service in a new project of type class library
  • Put your interfaces and implementations in this library in a namespace like MyServiceLib
  • Add to your web project a file like MyService.svc with only one statement, the ServiceHost directive:

    <%@ ServiceHost Service="MyServiceLib.MyService" %>
    

    where MyServiceLib is the name of the namespace of your WCF service and MyService the name of your service implementation class. (This simple setup is for the case when you deploy your service as a compliled assembly (in the Bin directory for instance). If you want to deploy with source and let complile on first request you need to put some more attributes to the service host directive (Programming language, Source file, etc.)

  • Put the configuration of the service into web.config in the <system.serviceModel> section.
like image 167
Slauma Avatar answered Oct 07 '22 03:10

Slauma