简体   繁体   English

WCF服务绑定设置

[英]WCF service binding settings

We have a WCF web service which is used fairly regularly on our site. 我们有一个WCF Web服务,该服务在我们的网站上经常使用。 Occasionally, we get a large amount of users to our site. 有时,我们会吸引大量用户访问我们的网站。 I don't want the service to timeout and am OK if it runs for over a minute if needs be. 我不希望服务超时,如果需要的话,它运行一分钟以上也可以。 I also want to set the amount of concurrent requests that can happen on the service. 我还想设置服务上可能发生的并发请求的数量。

I see there are lots of timeout settings that can be set on the binding - all with a default value of 1 minute. 我看到可以在绑定上设置很多超时设置-所有这些设置的默认值均为1分钟。 For a situation like this what timeout settings should I set and where can I set the max number of concurrent requests? 在这种情况下,应设置哪些超时设置,在哪里可以设置并发请求的最大数量?

Thanks 谢谢

In order to implement a scalable WCF web service, you need to, among other things, configure the proper concurrency mode, instancing model and service throttling setting. 为了实现可伸缩的WCF Web服务,除其他外,您需要配置适当的并发模式,实例化模型和服务限制设置。

Concurrency refers to the number of threads executing at the same time in a service instance. 并发是指在服务实例中同时执行的线程数。 By default, one thread executes, but if clients call multiple methods and each takes more than a short amount of time, you might want to use multiple threads. 默认情况下,一个线程执行,但是如果客户端调用多个方法并且每个方法花费的时间都不短,则可能要使用多个线程。

Instancing refers to the lifetime of a service instance. 实例化是指服务实例的生存期。 You can control instancing by setting the InstanceContextMode property of the ServiceBehavior attribute. 您可以通过设置ServiceBehavior属性的InstanceContextMode属性来控制实例化。 There are three possible values for this property: 此属性有三个可能的值:

  • PerSession . PerSession The WCF runtime creates a new service object the first time a client calls the service. WCF运行时在客户端第一次调用服务时创建一个新的服务对象。 It keeps the object active for subsequent calls by the client. 它将对象保持活动状态,以便客户端进行后续调用。 The runtime releases the object when the session ends. 会话结束时,运行时将释放对象。 This is the default value for this property. 这是此属性的默认值。
  • PerCall . PerCall The WCF runtime creates a new service object each time a client calls the service. 每次客户端调用服务时,WCF运行时都会创建一个新的服务对象。 It releases the object after the call. 调用后释放对象。
  • Single . Single The WCF runtime creates a new service object the first time a client calls the service. WCF运行时在客户端第一次调用服务时创建一个新的服务对象。 It keeps the object active for subsequent calls by any client. 它将对象保持活动状态,以供任何客户端进行后续调用。

The service throttling configuration controls the max number of instances, session and/or calls based on the instancing and concurrency mode settings. 服务限制配置根据实例和并发模式设置控制实例,会话和/或调用的最大数量。

<behaviors>
  <serviceBehaviors>
    <behavior  name="Throttled">
      <serviceThrottling 
        maxConcurrentCalls="x" 
        maxConcurrentSessions="x" 
        maxConcurrentInstances="x"
      />

The following articles should help you evaluate the various settings and choose the option best suited for your scenario. 以下文章应帮助您评估各种设置并选择最适合您的方案的选项。

http://msdn.microsoft.com/en-us/library/ff183865.aspx http://msdn.microsoft.com/en-us/library/ff183865.aspx
http://msdn.microsoft.com/en-us/library/ms731379%28v=vs.110%29.aspx http://msdn.microsoft.com/en-us/library/ms731379%28v=vs.110%29.aspx
http://msdn.microsoft.com/en-us/library/vstudio/ms735114%28v=vs.100%29.aspx http://msdn.microsoft.com/en-us/library/vstudio/ms735114%28v=vs.100%29.aspx

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

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