简体   繁体   中英

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?

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM