WCF服务中的优先级

时间:2012-08-14 12:05:40

标签: c# wcf web-services

目前,我在单个服务中有多个端点,它们调用相同的操作,但根据优先级具有不同的限制配置。

  <serviceBehaviors>
    <behavior name="PriorityService1">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="3" maxConcurrentSessions="3"
        maxConcurrentInstances="3" />
    </behavior>
    <behavior name="PriorityService2">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="5" maxConcurrentSessions="5"
        maxConcurrentInstances="5" />
    </behavior>
    <behavior name="PriorityService3">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceThrottling maxConcurrentCalls="10" maxConcurrentSessions="10"
        maxConcurrentInstances="10" />
    </behavior>
  </serviceBehaviors>

其中每个都以完全相同的方式处理传入的SOAP请求(它只是根据优先级限制它们)。每个优先级都只是继承自BaseService类。

public class Priority1Service : BaseService { }

public class Priority2Service : BaseService  { }

public class Priority3Service : BaseService  { }

如您所见,优先级类中没有实现,因为我只使用继承的行为。有一个更好的方法吗?有没有办法可以在soap消息中传递优先级,并让服务处理它?理想情况下,我希望能够摆脱只继承行为的这些类。

1 个答案:

答案 0 :(得分:1)

尝试在web.config文件中定义不同的服务配置;

<services>
      <service behaviorConfiguration="PriorityService1" name="Sample.Sample">
        ...
      </service>
      <service behaviorConfiguration="PriorityService2" name="Sample.Sample">
        ...
      </service>
      <service behaviorConfiguration="PriorityService3" name="Sample.Sample">
        ...
      </service>
</services>