Crudler
Crudler

Reputation: 2286

wcf multiple endpoints with a single address

I have imported a lot of wcf services into my app. for exaample

<endpoint address="http://localhost:1044/PersonSearchWebService.svc" behaviorConfiguration="ClientBehavior"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPersonSearchWebService"
            contract="WSPersonSearch.IPersonSearchWebService" name="BasicHttpBinding_IPersonSearchWebService" />
        <endpoint address="http://localhost:1044/TransferService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITransferService"
            contract="WSFileTransfer.ITransferService" name="BasicHttpBinding_ITransferService" />
        <endpoint address="http://localhost:1044/ScannedFileSearchWebService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IScannedFileSearchWebService"
            contract="WSScannedFileSearch.IScannedFileSearchWebService"
            name="BasicHttpBinding_IScannedFileSearchWebService" />

they all share in common the same server address. can i pull these out into a single variable therefore I only have to modify the config in one space when I move to the live server?

Thanks

Upvotes: 2

Views: 1613

Answers (1)

marc_s
marc_s

Reputation: 754200

You can define a base address in your service config and then use relative addresses in your endpoints based on that base address:

<service name=".....">
   <host>
      <baseAddresses>
         <add baseAddress="http://localhost:1044/" />
      </baseAddresses>
   </host>

   <endpoint name="BasicHttpBinding_IPersonSearchWebService"
       address="PersonSearchWebService.svc" 
       behaviorConfiguration="ClientBehavior"
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IPersonSearchWebService"
       contract="WSPersonSearch.IPersonSearchWebService"  />

    <endpoint name="BasicHttpBinding_ITransferService" 
        address="TransferService.svc"
        binding="basicHttpBinding"  
        bindingConfiguration="BasicHttpBinding_ITransferService"
        contract="WSFileTransfer.ITransferService" />

    <endpoint name="BasicHttpBinding_IScannedFileSearchWebService"
        address="ScannedFileSearchWebService.svc"
        binding="basicHttpBinding" 
        bindingConfiguration="BasicHttpBinding_IScannedFileSearchWebService"
        contract="WSScannedFileSearch.IScannedFileSearchWebService" />
</service>

Update: unfortunately, this feature only exists for the server side - there's no equivalent for the client side config.

On the client, you need to spell out all URL's in full - even if they share e.g. the server name and port.

Upvotes: 4

Related Questions