简体   繁体   English

使用WCF时如何使端点地址静态

[英]How to make endpoint address static while using wcf

I am hosting a web application using wcf service. 我正在使用wcf服务托管Web应用程序。 So whenever i add a new serviceReference This below code comes and sit in my web.config file which is obvious 因此,每当我添加新服务时,下面的代码就会出现,并位于我的web.config文件中,这很明显

  <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. 现在我的问题是每次添加serviceReference端点地址时都会添加。 I want to make that endpoint address Static. 我想将该端点地址设为静态。 Store somewhere in the web.Config. 存储在web.Config中的某个位置。

The idea behind the change is when i am going to host oon different server there might be more than 100 serviceReference. 更改背后的想法是,当我要在其他服务器上托管时,可能会有超过100个serviceReference。 So each time i cant change 100 endpoint address. 因此,每次我无法更改100个端点地址。 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. 在ISS上托管WCF服务之后,它将在静态addess上托管。 Something like "www.example.com/WcfService1/Service1.svc". 类似于“ 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. 现在,您要在其中使用该服务的Web应用程序(具有服务引用的位置)将具有带有客户端端点地址的web.config。 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 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. 您只需要在web.config文件中更改端点地址。 For services they can be still localhost , but for service consumers (mean client section in web.config ) they should contain real reachable host name. 对于服务,它们仍然可以是localhost ,但是对于服务使用者( web.config中的“平均client部分),它们应包含实际可访问的主机名。

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. 如果您的所有wcf服务都是公开的,并且应该可以从外部看到,则根据您的部署配置,这些服务将带有主机名。 And you should follow the suggestion of Shetty . 并且您应该遵循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. 如果应该将所有服务仅由公开的Web应用程序使用,并且不应从外部使用所有服务,则可以对诸如sales.servise.company.int products.service.company.int服务使用自定义DNS名称products.service.company.int并将其硬编码在web.config文件中。 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 在开发过程中,您只需在本地/ etc / hosts文件中指定这些主机名,在生产版本中,您可以执行相同的操作(在Web应用程序计算机上调整主机文件)或/并且将此DNS定义绑定到您的私有DNS服务器和负载均衡器中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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