WCF 类在同名的不同服务合约中实现两个操作合约

发布于 2024-08-31 21:06:30 字数 477 浏览 8 评论 0原文

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

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

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

我有一个实现这两个合同的类。我为两个合约创建了两个端点。但我无法从客户端代码访问该服务。 当我尝试将服务引用更新为以下内容时,它显示一个大错误:

元数据包含无法解决的错误....没有端点侦听...等。

我知道您不能有两个同名的 OperationContract 但有可能吗不同服务合同中有两个操作合同名称相同但签名不同?

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.

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?

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

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

发布评论

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

评论(2

始于初秋 2024-09-07 21:06:30

如果一项服务实现了这两个合约,那么您应该为您的操作合约指定唯一的名称。

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

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

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);
}
£烟消云散 2024-09-07 21:06:30

您可以使用以下内容。

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

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

You can use the following.

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

[ServiceContract]
public interface IContract2
{
    [OperationContract(Name = "Add2")]
    double Add(double ip);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文