简体   繁体   English

如何使WCF客户端异步?

[英]How do you make a WCF Client asynchronous?

I have a client that sends a request to a server, and the server answer to him. 我有一个客户端向服务器发送请求,服务器向他答复。

I want to do this in an asynchronous way. 我想以异步方式执行此操作。 The client sends a request, the server calculates it and returns it to a service in the client. 客户端发送一个请求,服务器进行计算并将其返回给客户端中的服务。 How can i do this? 我怎样才能做到这一点?

ps let's say the client wants to do add(int a, int b) and the server needs to send the result to a service that run on the client. ps假设客户端要执行add(int a,int b),服务器需要将结果发送到客户端上运行的服务。

A dual binding is only really needed when the server must send information to the client without a request. 仅当服务器必须在没有请求的情况下将信息发送到客户端时,才真正需要双重绑定。 Since you are making a request, use one of the more basic bindings. 由于您正在发出请求,因此请使用更基本的绑定之一。

Making the request asynchronous is all about what the client does when it calls the service. 使请求异步是关于客户端在调用服务时所做的一切。 One way of doing this is to get the generated client interface to include the event based asynchronous pattern . 一种方法是获取生成的客户端接口以包括基于事件的异步模式

When the client calls this method, it simply returns right away. 当客户端调用此方法时,它只是立即返回。 An event is then triggered when the actual response to the request is received. 当收到对请求的实际响应时,将触发一个事件。 The server itself is completely uninvolved with how the client waits for the response. 服务器本身完全不涉及客户端等待响应的方式。

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

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