The target assembly contains no service types. You may need to adjust the Code Access Security policy of this assembly." 目标程序集不包含服务类型。可能需要调整此程序集的代码访问
Did you ever encounter this dialog box when dealing with WCF services?
"The target assembly contains no service types. You may need to adjust the Code Access Security policy of this assembly."
It might happen when you run application at debug time. It is highly annoying and time consuming (it pauses application for more than one minute without any apparent reason). But what does it mean and why does it happen?
When you create a project from a WCF project templates Visual Studio knows that this project is a WCF service and thus it offers two debug time helpers: WCF Service Host and WCF Client. These two guys are intended to help you with running and testing WCF services without writing any code - they just appear at debug time. So far so good. But why the annoying dialog?
The dialog in question means that you have a project, created using one of the WCF project templates, 你有一个用WCF模板创建的项目with an interface marked with ServiceContract attribute这个项目中有一个接口被标记为服务契约 and in the same project you don't have a class that implements this interface但是在这个项目中,你却没有一个类去实现这个契约 (perhaps you implemented that interface in another project获取你是在别的项目中实现的这个接口). So, the WCF Service Host can't find a suitable class to host the service and it complains through that dreaded dialog box这样,WCF Server Host不能发现一个合适的类去宿主这个服务,于是就报出了那个窗口. Note that WCF Service Host is pretty dumb不灵活的 and it is incapable of不会 searching through other projects in same solution. OK, the solution is to stop running WCF Service Host or even better, instruct it which class implements the interface in question(VS应该的解决办法是停止运行WCF Service Host,通知一下是哪个类的哪个端口出错了). Well, AFAIK【As Far As I Know (就我所知)】 the later is impossible while the former can be done through project file modification using notepad. Here is how:
Delete this line from your project file:
<ProjectTypeGuids>{3D9AD99F-2412-4246-B90B-4EAA41C64699};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
And you won't see WCF Service Host or dreaded dialog anymore.
The question is, why didn't Microsoft think of these scenarios before?
BTW【By The Way 顺便(说一句)】, if you just want to stop WCF Client from runing ,then delete this command line argument: /client:"WcfTestClient.exe", created by WCF project template.
posted on 2013-05-01 18:35 YEKEYISHUO 阅读(318) 评论(0) 编辑 收藏 举报