WCF ServiceContract 和 svcutil 问题

发布于 2024-08-30 05:01:53 字数 887 浏览 4 评论 0原文

我有一个自动生成的公共接口 bu svcutil:

[System.ServiceModel.ServiceContractAttribute(Namespace="...", ConfigurationName="...")]
public interface MyInterface

然后我有 asmx Web 服务继承它并且工作正常。我正在尝试将其转换为 WCF,但是当我使用 ServiceContract 检测服务(在 asmx.cs 代码后面)时:

[ServiceContract(Namespace = "...")]
public class MyService : MyInterface 

此外,我还创建了 .svc 文件并在配置文件中添加了 system.serviceModel 设置。目标是将asmx服务迁移到WCF服务。

我收到此错误:

MyService 类型的服务类既定义了 ServiceContract,又从 MyInterface 类型继承了 ServiceContract。契约继承只能在接口类型之间使用。如果一个类使用 ServiceContractAttribute 进行标记,则它必须是层次结构中唯一具有 ServiceContractAttribute 的类型。

asmx 服务仍然可以正常工作。只有 .svc 给我带来了问题。我的问题是如何解决这个问题。 MyInterface 是一个接口,所以我不明白问题是什么以及为什么会出现错误。

注意我不想更改 MyInterface,因为它是从我的 wsdl 架构中的 svcutil 自动生成的,并且我不希望手动编辑此接口。整个想法是从 WSDL 自动生成服务类型,并通过手动编辑来节省我的团队开发工作。

任何帮助表示赞赏。

I have a public interface auto-generated bu svcutil:

[System.ServiceModel.ServiceContractAttribute(Namespace="...", ConfigurationName="...")]
public interface MyInterface

Then I have asmx web service inheriting it and working fine. I am trying ot convert it to WCF but when I instrument the service (in asmx.cs code behind) with ServiceContract:

[ServiceContract(Namespace = "...")]
public class MyService : MyInterface 

Also I have cerated .svc file and added the system.serviceModel setting in the config file. The goal is to migrate the asmx service to WCF service.

I've got this error:

The service class of type MyService both defines a ServiceContract and inherits a ServiceContract from type MyInterface. Contract inheritance can only be used among interface types. If a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute.

The asmx service is still working fine. Only the .svc is giving me issues. My question is how to fix that. MyInterface is an interface so I do not see what the problem is and why I've got the error anyway.

Note I do not want to change MyInterface, because it is autogenerated from svcutil from my wsdl schema and I do not want this interface to be edited manually. The whole idea is to have the service types automatically genereted from WSDL and to save my team development efforts with manual editing.

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2024-09-06 05:01:53

您需要从 MyService 类中删除 ServiceContractAttribute。该属性已在接口中定义,这是指定该接口将公开为 WCF 服务的正确方法。

You need to remove the ServiceContractAttribute from MyService class. This attribute is already defined in the interface and that's the correct way of specifying that this interface will be exposed as WCF service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文