Search code examples
c#.netwcf.net-4.0service-reference

How do you add a WCF service reference with a fixed port?


I have a WCF service being hosed by a Windows Service with this in the app.config

  <services>
    <service behaviorConfiguration="serviceBehavior" name="AgileServer.AgileService">
      <endpoint address="AgileService" binding="basicHttpBinding" name="basicHttp" contract="AgileServer.AgileService" />
      <endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:24453/AgileService" />
        </baseAddresses>
      </host>
    </service>

When I try to add a service reference to my service (by clicking "Discover" in the "Add Service Reference" prompt), the URI shows up as http://localhost:33908/AgileService.svc I want my service to use http://localhost:24453/AgileService as the URI. How can I accomplish this?


Solution

  • You need to

    • have the WCF service in your Windows service up and running
    • do not click on Discover, but instead type in / paste in the URL you want to connect to - either use the base address (http://localhost:24453/AgileService) or the MEX endpoint's address (http://localhost:24453/AgileService/mex)

    Doing this will connect to the URL defined, and the service metadata will be retrieved and used to create a client-side proxy for the service.

    Just as a side-note: your actual service URL will be:

    http://localhost:24453/AgileService/AgileService
    

    made up of your base address (http://localhost:24453/AgileService) plus the relative address on the endpoint (AgileService).