简体   繁体   English

单独组装中的WCF服务

[英]WCF Service in Separate Assembly

在单独的程序集中创建WCF服务但在同一解决方案中通过Web项目公开其端点的正确方法是什么?

I've done it this way: 我这样做了:

  • Build your WCF service in a new project of type class library 类库类的新项目中构建WCF服务
  • Put your interfaces and implementations in this library in a namespace like MyServiceLib 将您的接口和实现放在像MyServiceLib这样的命名空间中
  • Add to your web project a file like MyService.svc with only one statement, the ServiceHost directive: 向您的Web项目添加一个像MyService.svc这样的文件,只有一个语句ServiceHost指令:

     <%@ 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. 其中MyServiceLib是WCF服务和的命名空间的名称MyService服务实现类的名称。 (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.) (这种简单的设置适用于将服务部署为compliled程序集的情况(例如,在Bin目录中)。如果要在第一次请求时使用source和let complile进行部署,则需要向服务主机添加更多属性指令(编程语言,源文件等)

  • Put the configuration of the service into web.config in the <system.serviceModel> section. 将服务配置放入<system.serviceModel>部分的web.config中。

我更喜欢在自己的程序集中分离我的契约实现 ,这有助于在未来的基础上实现基于相同合同的替代实现。

如果您同时控制服务器和客户端,则可以使用此链接中描述的方法: http//www.dnrtv.com/default.aspx?showNum = 122

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM