views:

63

answers:

1

I need some help configuring WCF to support multiple environments. One environment allows anonymous authentication over standard HTTP and the other uses Windows Authentication over SSL.

I can configure WCF to support either of the environments, but not both within the same web.config file.

Here's what allows anonymous over http:

<behaviors>
    <serviceBehaviors>
        <behavior name="MexBehavior" >
            <serviceMetadata httpGetEnabled="true" />
        </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
        <behavior name="DLAspNetAjaxBehavior">
            <enableWebScript/>
        </behavior>
        <behavior name="Service1AspNetAjaxBehavior">
            <webHttp/>
        </behavior>
    </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
    <service name="DL" behaviorConfiguration="MexBehavior">
        <endpoint address="" behaviorConfiguration="DLAspNetAjaxBehavior" binding="webHttpBinding" contract="DLService"/>
        <endpoint name="MEXEndpoint" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
    <service name="Service1" behaviorConfiguration="MexBehavior">
        <endpoint address="" behaviorConfiguration="Service1AspNetAjaxBehavior" binding="webHttpBinding" contract="Service1"/>
        <endpoint name="MEXEndpoint" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>          
</services>

And here's what works for Windows Authentication over SSL:

<behaviors>
    <serviceBehaviors>
        <behavior name="MexBehavior" >
            <serviceMetadata httpGetEnabled="true" />
        </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
        <behavior name="DLAspNetAjaxBehavior">
            <enableWebScript/>
        </behavior>
        <behavior name="Service1AspNetAjaxBehavior">
            <webHttp/>
        </behavior>
    </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
    <service name="DL" behaviorConfiguration="MexBehavior">
        <endpoint address="" behaviorConfiguration="DynamicLoaderAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webWinBinding" contract="DLService"/>
        <endpoint name="MEXEndpoint" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
    <service name="Service1" behaviorConfiguration="MexBehavior">
        <endpoint address="" behaviorConfiguration="ValidValuesServiceAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webWinBinding" contract="Service1"/>
        <endpoint name="MEXEndpoint" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>          
</services>     
<bindings>
    <webHttpBinding>
        <binding name="webWinBinding">
            <security mode="Transport">
                <transport clientCredentialType="Windows" />
            </security>
        </binding>
    </webHttpBinding>           
</bindings>

When I add the endpoint from the SSL configuration to the non-SSL configuration, the anonymous service breaks.

Here is the config file that doesn't work but attempts to put both settings together:

<behaviors>
    <serviceBehaviors>
        <behavior name="MexBehavior" >
            <serviceMetadata httpGetEnabled="true" />
        </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
        <behavior name="DLAspNetAjaxBehavior">
            <enableWebScript/>
        </behavior>
        <behavior name="Service1AspNetAjaxBehavior">
            <webHttp/>
        </behavior>
    </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
    <service name="DynamicLoader" behaviorConfiguration="MexBehavior">
        <endpoint name="basic" address="" behaviorConfiguration="DLAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webAnonymousBinding" contract="DLService"/>
        <endpoint name="secure" address="" behaviorConfiguration="DLAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webWinBinding" contract="DLService"/>
        <endpoint name="MEXEndpoint" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
    <service name="ValidValuesService" behaviorConfiguration="MexBehavior">
        <endpoint name="basic" address="" behaviorConfiguration="Service1AspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webAnonymousBinding" contract="Service1"/>
        <endpoint name="secure" address="" behaviorConfiguration="Service1AspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webWinBinding" contract="Service1"/>
        <endpoint name="MEXEndpoint" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
</services>
<bindings>
    <webHttpBinding>
        <binding name="webWinBinding">
            <security mode="Transport">
                <transport clientCredentialType="Windows" />
            </security>
        </binding>
        <binding name="webAnonymousBinding">
            <security mode="None">
            </security>
        </binding>
    </webHttpBinding>
</bindings>

Is there some way I can combine the endpoints into one web.config to support the two environments?

A: 

Does this previous SO question/answer help?

http://stackoverflow.com/questions/951204/calling-a-web-service-using-wcf-over-http-and-https

(See the first answer.)

David Hoerster
No, it doesn't work for me. I will edit the question to show the combined config file that doesn't work. Thanks!
Chris Conway