开发者

WCF Service in Separate Assembly

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?


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.


I prefer separating my contracts and implementations in their own assemblies, this lends itself to alternate implementations based on the same contracts down the road.


If you have control of both the server and the client you could use the method described in this link: http://www.dnrtv.com/default.aspx?showNum=122

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜