WCF类实现在具有相同名称不同的服务合同两种操作合同 [英] WCF class implementing two operation contracts in different service contracts with same name

查看:298
本文介绍了WCF类实现在具有相同名称不同的服务合同两种操作合同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经声明了两个服务合同如下:

I have declared two service contracts as follows:

[ServiceContract]
public interface IContract1
{
    [OperationContract]
    double Add(int ip);
}

[ServiceContract]
public interface IContract2
{
    [OperationContract]
    double Add(double ip);
}



我有一个实现上述两个合同的类。我创建了两个端点两个合同。但我不能够从客户端代码访问该服务。
,当我尝试更新服务引用,因为它显示一个大错误:

I have a class which implements these two contracts. I have created two endpoints for both contracts. But I'm not able to access the service from client code. It displays a big error when I try to update the service reference as:

元数据包含无法解析错误。 ......有没有终点在听...等。

Metadata contains an error that cannot be resolved.... There was no endpoint listening at ... , etc.

我知道,你不能有两个 OperationContract的 s的名称相同,但有可能有与同名但不同的签名?

I know that you can't have two OperationContracts with the same name but is it possible to have two operation contracts in different service contracts with same name but different signature?

推荐答案

如果一个服务同时实现了合同,那么你应该给你的业务合同唯一的名称。

If one service implements both contracts then you should give unique names to your operation contracts.

[ServiceContract]
public interface IContract1
{
    [OperationContract(Name="AddInt")]
    double Add(int ip);
}

[ServiceContract]
public interface IContract2
{
    [OperationContract(Name="AddDouble")]
    double Add(double ip);
}

这篇关于WCF类实现在具有相同名称不同的服务合同两种操作合同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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