【问题标题】:Add web service with 2 interfaces添加具有 2 个接口的 Web 服务
【发布时间】:2014-02-13 18:02:19
【问题描述】:

我正在将 Web 服务从 VB 更新到 C#。这是 WCF 服务。 Web 服务实现了 2 个接口。 当我将 Web 服务添加到测试应用程序时,只能访问其中一个接口。 当我尝试从第二个接口调用方法时,无法识别方法签名。

这在 VB 中有效,我希望我可以在 C# 中做同样的事情。 这是网络服务类的实现:

支付服务接口:

namespace PayService
{
    [ServiceContract (Namespace...)]
    public interface IPayService
    {
        //Initiate a credit card authorization.
        [OperationContract(IsOneWay = true)]
        void Authorize(...12 arguments here...);
}

PayService2 接口:

namespace PayService2
    {
        [ServiceContract (Namespace...)]
        public interface IPayService
        {
            //Initiate a credit card authorization.
            [OperationContract(IsOneWay = true)]
            void Authorize(...13 arguments here...);
    }


public partial class PayService : IPayService, IPayService2
{
  Authorize(...there are 12 arguments here)
  Authorize(...there are 13 arguments here)
  ...more methods but they are not a problem.
}

调用应用程序只是一个用于测试 Web 服务的 Web 应用程序。

//Create instance of PayService
PayService.PayServiceClient payService = new PayService.PayServiceClient();
payService.Authorize(...12 arguments)  //this one works fine

payService.Authorize(...13 arguments)  //this one is not recognized

有谁知道为什么不是所有方法都在使用 PayService 的 Web 应用程序中可见?

谢谢。

【问题讨论】:

  • 这是 WCF 服务吗?
  • 不,如果不告诉我们您是如何实现调用此网络服务的,我们谁都无法帮助您。我们不是通灵者,抱歉:)
  • 对不起...我添加了更多细节。这些信息够吗?
  • OperationContract 的想法有帮助吗? stackoverflow.com/a/5689054/404
  • 我将 'Name=' 属性添加到 OperationContract 中,但 Web 应用程序仅识别其中一种 Authorize 方法。其次,我读到操作是由方法签名定义的,而不仅仅是方法名称。我可以有 2 个名称相同但签名不同的方法吗?

标签: c# web-services interface


【解决方案1】:

看看这个:https://stackoverflow.com/a/720389/487940

您基本上想将 2 个接口组合成一个接口,如下所示:

public interface IMyInterface : IInterface1, IInterface2

【讨论】:

  • 那个链接非常好。第二个答案有一个链接,该链接解释了如何使用 2 个接口为同一服务拥有多个端点。如果我能让它发挥作用,那就是我所需要的。这是评论和链接:单个 ListenUri 的多个端点:msdn.microsoft.com/en-us/library/aa395210.aspx
  • 这对我不起作用,因为我在两个接口中都有一个名称相同但方法签名不同的方法...请参阅上面的参数列表。看来我将不得不使用多端点实现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-28
  • 2017-02-25
  • 1970-01-01
相关资源
最近更新 更多