目标程序集不包含服务类型.您可能需要调整此程序集的代码访问安全策略 [英] The target assembly contains no service types. You may need to adjust the Code Access Security policy of this assembly

查看:43
本文介绍了目标程序集不包含服务类型.您可能需要调整此程序集的代码访问安全策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 2 种方法的小型 WCF 解决方案,但在构建它时出现此错误.
如果我在没有取消的情况下留言,我会收到

I have a small WCF solution with 2 methods but am getting this error when I build it.
If I leave the message without dismissing it, I get

WCF Service Host cannot find any service metadata. This may cause the client application to run improperly. Please check if metadata is enabled.

我很确定我的配置是错误的,可能定义的端点与命名空间不匹配,但我不确定要在哪里设置.

I'm pretty sure my config is wrong, probably the defined endpoint does not match the namespace but I'm not sure what to set where.

Contracts 类的命名空间是 JOB_1_0_Service.Contracts,有 2 个方法.在这个项目的APP.Config中是这样的:

The namespace of the Contracts class is JOB_1_0_Service.Contracts with 2 methods. In the APP.Config of this project is the following:

<endpoint address="/Address1" binding="wsHttpBinding" contract="JOB_1_0_Service.Contracts.IService">

合约方法定义为:

[ServiceContract]
public interface IService
{
    [OperationContract]
    GetNearbyJobsResponse GetNearbyJobs(GetNearbyJobsRequest request);

    [OperationContract]
    GetChildJobsResponse GetChildJobs(GetChildJobsRequest request);
}

实现类的命名空间又是JOB_1_0_Service.Implementation,有2个方法:

The namespace of the implementation class is JOB_1_0_Service.Implementation again with 2 methods:

GetNearbyJobsResponse IService.GetNearbyJobs(GetNearbyJobsRequest request)
{
    ...
}

GetChildJobsResponse IService.GetChildJobs(GetChildJobsRequest request)
{
    ...
}

我应该在哪个配置文件中放什么 - 如果确实是这个问题?

What should I put in which config file - if indeed this is the problem?

[更新]

好的,再重复一遍:我在 1 个解决方案中有 2 个项目.1 个项目包含合约,另一个项目包含实现代码.

Ok, so just to re-iterate: I have 2 projects in 1 solution. 1 project contains the contracts and the other has the implementation code.

这也意味着有 2 个配置文件.到目前为止我不知道哪一个需要以什么方式修改.

This also means there are 2 config files. So far I don't know which one needs modding in what way.

那么,哪个是要修改的,还是两个都需要修改?我假设实施项目是用于 WCF 配置的项目.

So, which is the one to modify, or do I need to modify both? I assume the implementation project is the one for the WCF config.

我现在的情况是,当我构建它时说我没有公开元数据,但它也尝试(但失败)将合约公开为端点!

I'm now in the situation where, when I build it says I have no metadata exposed, and yet it also tries (and fails) to expose a contract as an endpoint!

[/更新]

推荐答案

我遇到了同样的错误,因为我错误地注释掉了 [ServiceContract] 属性.取消注释 [ServiceContract] 属性后,一切正常.

I was getting the same error becuase I had mistakenly commented out the [ServiceContract] attibute. Once I uncommented the [ServiceContract] attribute it all worked okay.

我希望这能帮助面临同样问题的其他人.

I hope this help others who face the same issue.

这篇关于目标程序集不包含服务类型.您可能需要调整此程序集的代码访问安全策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆