简体   繁体   English

使用同一客户端实例对WCF服务进行多方法调用

[英]Multiple method call using same client instance to WCF service

My WPF application is calling the WCF service using a single client object. 我的WPF应用程序正在使用单个客户端对象调用WCF服务。 This is working fine when request is sent and response is coming immediately before next request. 发送请求并且在下一个请求之前立即有响应时,此方法工作正常。

When I am sending the first request and it is taking 3 minutes to complete the calculation task and return the result. 当我发送第一个请求时,需要3分钟才能完成计算任务并返回结果。 In the meanwhile second request is sent from my WPF application (ping request is sent every 3 second). 同时,我的WPF应用程序发送了第二个请求(ping请求每3秒发送一次)。 At this time, I am getting the following error and WPF application getting disconnected: 这时,出现以下错误,WPF应用程序断开连接:

The server did not provide a meaningful reply: this might be caused by a contract mismatch, a prematured session shutdown or an internal server error 服务器未提供有意义的答复:这可能是由于合同不匹配,会话提前关闭或服务器内部错误引起的

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state. 通信对象System.ServiceModel.Channels.ServiceChannel由于处于故障状态,因此无法用于通信。

My service behavior is written as follows: 我的服务行为如下所示:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults=true)]

I tried different combination and it is not working. 我尝试了不同的组合,但无法正常工作。

如果您从singel客户端进行多个并发调用,则除了InstanceContextMode之外,还应将ConcurrencyMode设置为Multiple。请注意,如果将InstanceContextMode设置为Single,则您的服务将作为Singleton,那么您应该注意操纵变量,因为它对其他变量有反射打电话..

Your Ping request should not use the same Channel. 您的Ping请求不应使用同一频道。 It should open it's own channel. 它应该打开自己的频道。 Ideally, every independent request should open it's own channel (alternatively, you could build a queuing system). 理想情况下,每个独立的请求都应打开其自己的通道(或者,您可以构建一个排队系统)。 But accessing the same channel from two different threads is not going to work. 但是从两个不同的线程访问相同的通道将无法正常工作。

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

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