Rob Bowman
Rob Bowman

Reputation: 8711

WCF Single Service Implemation, Multiple Behaviours. Possible

I have an IIS7 hosted service that I need to expose to two different clients. For one of the client I need to enforce a more strict Throttling behaviour than the other.

This means I need to define Two tags and because these can only be referenced from a tag, then I need two of these also?

I have defined the following web.config. Problem is, when I try to browse to either service so that I can pull the metadata then I get the following error:

Parser Error Message: A child element named 'service' with same key already exists at the same configuration scope.
Collection elements must be unique within the same configuration scope (e.g. the same application.config file). Duplicate key value:  'WCFTwoEndpoints.Calculate'.

Am I going about this the right way?

<system.serviceModel>
    <services>
      <service name="WCFTwoEndpoints.Calculate" behaviorConfiguration ="NotThrottled">
        <endpoint address="http://localhost/WCFTwoEndpoints/Calculate.svc"
          binding="wsHttpBinding" bindingConfiguration="" name="Calculator"
          contract="WCFTwoEndpoints.ICalculate" />
        <endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
      </service>
      <service name="WCFTwoEndpoints.Calculate" behaviorConfiguration ="Throttled">
        <endpoint address="http://localhost/WCFTwoEndpoints/ThrottledCalculate.svc"
          binding="wsHttpBinding" bindingConfiguration="" name="ThrottledCalculator"
          contract="WCFTwoEndpoints.ICalculate" />
        <endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NotThrottled">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="Throttled">
          <serviceMetadata httpGetEnabled="true" />
          <serviceThrottling maxConcurrentCalls="19" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

Upvotes: 5

Views: 4274

Answers (1)

Buh Buh
Buh Buh

Reputation: 7546

You are a little stuck, because the name of the key must match exactly the name of your service class.

The only way around this I can think of, would be to create a new class which inherits from WCFTwoEndpoints.Calculate. Then you would have a distinct name. It's not very nice though.

 

I think if you asked the WCF designers why they designed it like this, they would say that a serivce is supposed to be indepent of the client. What you want here is not really a single service; but two different independant services which just happen to have some implementation in common. From the clients point of view they would not behave like one single service.

Upvotes: 7

Related Questions