【问题标题】:WCF <operation>Async methods not generated in proxy interfaceWCF <操作>代理接口中未生成异步方法
【发布时间】:2010-03-30 15:10:29
【问题描述】:

我想在我的 WCF 服务客户端代理上使用 &lt;operation&gt;Asnyc 方法而不是 Begin&lt;operation&gt;/End&lt;operation&gt;,因为我正在更新 WPF 控件并且需要确保它们是从 UI 线程更新的。我可以使用 Dispatcher 类为 UI 线程排队项目,但这不是我要问的......

我已经配置了服务引用来生成异步操作,但它只生成代理实现中的方法,而不是接口。该接口只包含同步和Begin&lt;operation&gt;/End&lt;operation&gt;方法。

为什么接口中没有生成这些方法,有没有办法做到这一点,还是我必须创建派生接口才能手动添加它们?

【问题讨论】:

    标签: c# wcf asynchronous wcf-proxy


    【解决方案1】:

    我最终像这样手动创建了自己的界面:

    public interface IMyServiceProxy : IGeneratedServiceProxy
    {
       void GetEntityAsync(GetEntityRequest request);
       void GetEntityAsync(GetEntityRequest request, object userState);
       event EventHandler<GetEntityCompletedEventArgs> GetEntityCompleted;
    }
    

    然后创建一个实现我的接口的派生类:

    public class MyServiceProxy : GeneratedServiceProxy, IMyServiceProxy
    {
    }
    

    如果有人找到更好的解决方法,请告诉我。

    【讨论】:

      【解决方案2】:

      您的项目需要以 .NET Framework 3.5 为目标才能生成基于事件的代理。 请参阅“如何启用”部分here

      【讨论】:

        猜你喜欢
        • 2014-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-01
        • 2018-07-24
        • 2013-11-03
        • 1970-01-01
        • 2011-04-24
        相关资源
        最近更新 更多