简体   繁体   English

WCF客户最佳实践

[英]WCF Client best practice

We are facing timeout issue when calling some of the WCF Operations. 调用某些WCF操作时,我们面临超时问题。

We are not explicitly closing the connection. 我们没有明确关闭连接。 Could this be causing the issue? 这可能是造成问题的原因吗? The number of users on site is pretty low and maxconcurrentsession on server is set to 150. 站点上的用户数量很少,服务器上的maxconcurrentsession设置为150。

We have 20 methods on client side that calls the service. 我们在客户端调用服务的方法有20种。 Do we need to do below on all the methods that call service? 下面是否需要对调用服务的所有方法进行操作?

  1. Open Connection 打开连接
  2. Call Service 电话服务
  3. Close Connection 紧密连接
  4. Any exception Abort. 任何异常中止。

If we don't close the connection, does WCF automatically closes the connection? 如果我们不关闭连接,WCF是否会自动关闭连接?

Thanks. 谢谢。

You should do 4 step above. 您应该在上面执行4步。

If you don't close connection. 如果您不关闭连接。 Anytime service meet an error, you cann't call service on existent connection. 每当服务遇到错误时,您就无法在现有连接上调用服务。 Error such as: 错误如:

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

Refer for best practices: http://www.codeproject.com/Articles/622989/WCF-and-the-Try-Catch-Abort-Pattern 请参考最佳做法: http : //www.codeproject.com/Articles/622989/WCF-and-the-Try-Catch-Abort-Pattern

WCF service operations has default value of sendTimeOut is 1 Minute. WCF服务操作的sendTimeOut的默认值为1 Minute。 To increase it you can set this value in both either in coding or in configuration. 要增加它,可以在编码或配置中都设置此值。

From here : 这里

  1. SendTimeout – used to initialize the OperationTimeout, which governs the whole process of sending a message, including receiving a reply message for a request/reply service operation. SendTimeout –用于初始化OperationTimeout,它控制发送消息的整个过程,包括接收请求/答复服务操作的答复消息。 This timeout also applies when sending reply messages from a callback contract method. 当从回调协定方法发送回复消息时,此超时也适用。

  2. OpenTimeout – used when opening channels when no explicit timeout value is specified OpenTimeout –在未指定显式超时值的情况下打开通道时使用

  3. CloseTimeout – used when closing channels when no explicit timeout value is specified CloseTimeout –在未指定显式超时值的情况下关闭通道时使用

You need to update value in client as well as in server configuration (Or Update on service and then Update client Proxies) as below, this will set all timeout values to 10 minute. 您需要按以下方式更新客户端和服务器配置中的值(或先更新服务,然后再更新客户端代理),这会将所有超时值设置为10分钟。

<configuration>
<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding openTimeout="00:10:00"
               closeTimeout="00:10:00"
               sendTimeout="00:10:00"
               receiveTimeout="00:10:00">
      </binding>
    </wsHttpBinding>
  </bindings>
</system.serviceModel>

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

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