Update Service Reference modifies the service url from localhost to machinename

BENOIT Frederic 0 Reputation points
2023-04-28T08:57:50.48+00:00

I have exact same problem as in here, still problematic nearly 15 years later:

  • I have a project with a service reference in Visual Studio 2017, with source code control.
  • The referenced service is implemented by another Web Application (.NET Framework) project in the same solution ; therefore it is normal for each developer in the team to work with their own local copy of the service, and thus for the service reference to point to localhost.
  • The service reference is set to http://localhost/servicename
  • I right-click and Update Service Reference
  • BAD: The service reference is now set to http://machinename/servicename. This is undesired behavior. If developer Bob updates the service reference and carelessly checks in, developer Carol will unwittingly target developer Bob's service, and not see her own implementation changes until she notices the URL was changed under her feet and even Bob didn't know!
  • How can I avoid this? How can I ensure a localhost service reference stays localhost without needing to manually revert it in web.config every time I update?
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,532 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiayao Wu-MSFT 186 Reputation points Microsoft Vendor
    2023-05-02T08:29:14.3+00:00

    Hi @BENOIT Frederic ,

    You can try the following steps :

    • Add the IP to endpoint address and add a host name with the base IP address :
    <endpoint
      address="http://xx.xx.xx.xx/ServiceApp/Service.svc"
      binding="basicHttpBinding" contract="IService">
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://xx.xx.xx.xx/ServiceApp/" />
      </baseAddresses>
    </host>
    
    
    • Add the domain name to the host header in IIS if you have.
    • Add the IP address and computer name to the clients hosts file.

    Best Regards,

    Jiayao Wu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.