简体   繁体   中英

How to make endpoint address static while using wcf

I am hosting a web application using wcf service. So whenever i add a new serviceReference This below code comes and sit in my web.config file which is obvious

  <endpoint address="http://localhost:8426/WcfService1/Service1.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
    contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />

Now my question is everytime when i add serviceReference endPoint address will be added. I want to make that endpoint address Static. Store somewhere in the web.Config.

The idea behind the change is when i am going to host oon different server there might be more than 100 serviceReference. So each time i cant change 100 endpoint address. So how to make it static and access it.

After you host your WCF service on ISS, it will be hosted on a static addess. Something like "www.example.com/WcfService1/Service1.svc". Now the web application where you want to consume this service, where you have the service reference will have web.config with client end point address. You have to manually replace this. If you are concerned about updating this in multiple services, look into Build Deployment Configurations. Build deployment techniques have options to replace these configuration values in config files based on environment where you are deployein the buiuld.

http://www.asp.net/web-forms/overview/deployment/configuring-team-foundation-server-for-web-deployment/creating-a-build-definition-that-supports-deployment

When service references once generated for localhost you do not need regenerate them after deployment. You just need to change endpoint addressers in your web.config files. For services they can be still localhost , but for service consumers (mean client section in web.config ) they should contain real reachable host name.

If all your wcf services are public and supposed to be visible from the outside, they will be available with host names, according to your deployment configuration. And you should follow the suggestion of Shetty .

But you can use different build/deployment systems, where some kind of templates for config files can be used, and host names would be replaced with real host names during deployment.

If all your services are supposed to be used only by web application, which is public, and all the services should not be available from the outside, it can make sense to use custom DNS names for services like sales.servise.company.int products.service.company.int and hardcode them in web.config files. During development you simply specify those host names in your local /etc/hosts file, and in production release you can do same (tweak hosts file on web application machine) or/and bind this DNS definition in your private DNS server and load balancer

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