【问题标题】:I added a callback interface method to my existing WCF service, but updating my service reference I don't see it我向我现有的 WCF 服务添加了一个回调接口方法,但更新我的服务引用我没有看到它
【发布时间】:2014-04-01 18:18:08
【问题描述】:

我最近在我的服务中添加了一个 ping 方法,它在回调通道上调用了一个 pong 方法:

public partial class myService
{
    public void Ping()
    {
        OperationContext.Current.GetCallbackChannel<IKeepAliveEvents>().Pong();
    }
}

我还在pong方法中添加了回调接口:

namespace myService
{
    [ServiceContract]
    public interface IKeepAliveEvents
    {
        [OperationContract(IsOneWay = true)]
        void Pong();
    }
}

在我的 WCF 服务的主接口定义中继承:

[ServiceContract]
public interface IMyServiceEvents : IEvents1, IEvents2, ..., IEvents9, IKeepAliveEvents
{
    [OperationContract(IsOneWay = true)]
    void TestEvent(string s);
}

然后按如下方式使用:

[ServiceContract(CallbackContract=typeof(IMyServiceEvents)]
public interface IMyService : ISomething1, ISomething2, ..., ISomething13
{
    ...
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, MaxItemsInObjectGraph = 2147483647)]
public partial class myService : IMyService, IDisposable, IServiceBehavior, IErrorHandler {
    ...
}

问题是......当我的 WCF 服务正在运行时,它不会让我从接口定义中在我的客户端应用程序中实现 pong 方法,因为每次我尝试更新服务时它似乎都不存在...并且可以肯定我正在正确的 URL 更新正确的服务,并且可以肯定我使用的是最新版本的代码,因为我已经能够将调试器附加到我的服务并在 Ping 方法中放置一个断点它叫乒乓。更奇怪的是,Ping 方法确实存在供我的客户端使用,但 Pong 方法似乎并不想出现在客户端这里:

public partial class myClientEndpoint : myServiceCallback {
    // I would expect Pong to be implementable here.
}

可能是什么问题?

【问题讨论】:

    标签: c# web-services wcf visual-studio service


    【解决方案1】:

    答案实际上是我的 IKeepAlive 的 ServiceContract(包含 Ping 方法)没有将其自己的回调合同引用为 IKeepAliveEvents...就像这样:

    [ServiceContract(CallbackContract=typeof(IKeepAliveEvents))]
    public interface IKeepAlive
    {
        [OperationContract(IsOneWay = true)]
        public void Ping();
    }
    

    在 MyServiceContract 上指定 [ServiceContract(CallbackContract=typeof(IMyServiceEvents)] 是不够的。 WCF 不能以这种方式进行继承。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多