简体   繁体   English

世界足球联合会 <operation> 代理接口中未生成异步方法

[英]WCF <operation>Async methods not generated in proxy interface

I want to use the <operation>Asnyc methods rather than the Begin<operation>/End<operation> on my WCF service client proxy because I'm updating WPF controls and need to make sure they're being updated from the UI thread. 我想在WCF服务客户端代理上使用<operation>Asnyc方法而不是Begin<operation>/End<operation> ,因为我正在更新WPF控件,并且需要确保它们是从UI线程中更新的。 I could use the Dispatcher class to queue items for the UI thread but that's not what I'm asking about.. 我可以使用Dispatcher类将UI线程的项目排队,但这不是我要的。

I've configured the service reference to generate the asynchronous operations, but it only generates the methods in proxy's implementation, not it's interface. 我已经配置了服务引用来生成异步操作,但是它仅在代理的实现中生成方法,而不是在接口中生成方法。 The interface only contains synchronous and Begin<operation>/End<operation> methods. 该接口仅包含同步方法和Begin<operation>/End<operation>方法。

Why aren't these methods generated in the interface and is there a way to do this, or do I have to create a derived interface to manually add them? 为什么在界面中没有生成这些方法,有什么方法可以做到呢?还是我必须创建一个派生的接口来手动添加它们?

I ended up creating my own interface manually like this: 我最终手动创建了自己的界面,如下所示:

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

and then creating a derived class which implements my interface: 然后创建一个实现我的接口的派生类:

public class MyServiceProxy : GeneratedServiceProxy, IMyServiceProxy
{
}

Let me know if anyone finds a better workaround. 让我知道是否有人找到更好的解决方法。

Your project needs to target .NET Framework 3.5 in order to generate event-based proxies. 您的项目需要以.NET Framework 3.5为目标,以便生成基于事件的代理。 See " How to enable " section here . 请参阅此处的如何启用 ”部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM