Mutiple http base address for self hosted WCF service?

1.5k Views Asked by At

I have a WCF service that has one http endpoint, I would like to add another http endpoint address with a different binding. The service is not hosted in IIS and hence setting the multipleSiteBindingsEnabled is of no use.

Am trying something like this.

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

    <services>
            <service behaviorConfiguration="ServiceBehaviorConfiguration"
             name="ServerService">
                <endpoint address="http://localhost:6732/ServerService" binding="webHttpBinding" behaviorConfiguration="webby"
         contract="IClientAppContract">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="http://localhost:800/ServerService" binding="basicHttpBinding"
         contract="IClientAppContract">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:800/ServerService" />
                        <add baseAddress="http://localhost:6732/ServerService" />
                    </baseAddresses>
                </host>
            </service>
        </services>
</system.serviceModel>
2

There are 2 best solutions below

0
On

You could create two services that each have their own different baseAddress, but their internal endpoints are identical.

2
On

Try something like the config shown below. It exposes multiple endpoints through a single port but I'm sure this pattern of configuration is supported by WCF.

    <services>
        <service behaviorConfiguration="ServiceBehaviorConfiguration"
                 name="ServerService">
            <endpoint address=""
                      binding="webHttpBinding"
                      behaviorConfiguration="webby"
                      contract="IClientAppContract">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="basic"
                      binding="basicHttpBinding"
                      contract="IClientAppContract">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:800/ServerService" />
                </baseAddresses>
            </host>
        </service>
    </services>