简体   繁体   English

使用URL调用wcf服务而不是ip或localhost

[英]Use URL to call wcf service instead of ip or localhost

I hosted my WCF service on one static IP but when net disconnected then dynamic IP of system changes so my service stop working. 我将WCF服务托管在一个静态IP上,但是当网络断开连接时,系统的动态IP发生了变化,因此我的服务停止工作。

Now what I want to do is instead of using IP address or localhost I want to call service using URL. 现在,我要执行的操作不是使用IP地址或本地主机,而是要使用URL调用服务。

This is my web.con file code for 这是我的web.con文件代码

<system.serviceModel>
<services>
    <service name="abc.bca" behaviorConfiguration="mexendpoint">
      <endpoint address="" binding="basicHttpBinding" contract="abc.Ibca">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost/bca.svc" />
        </baseAddresses>
      </host>
    </service>
</services>

And this is how I define an IP address for calling through mobile application suppose that below is my static IP. 假设下面是我的静态IP,这就是我定义用于通过移动应用程序调用的IP地址的方式。

117.87.21.12

So instead of call static IP can I redirect it to any URL like techit@.com 因此,除了调用静态IP之外,我还可以将其重定向到任何网址,例如techit @ .com

The issue is more related to Domain Name System. 该问题与域名系统有关。 Generally, we could call the service with the computer name. 通常,我们可以使用计算机名称来调用该服务。

http://myserverhostname:xxx/service.svc http:// myserverhostname:xxx / service.svc

If we want to add the custom domain name, we should have an understanding on the DNS system, 如果要添加自定义域名,则应该对DNS系统有所了解,
https://en.wikipedia.org/wiki/Domain_Name_System https://zh.wikipedia.org/wiki/域名_系统
https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/plan/reviewing-dns-concepts https://docs.microsoft.com/zh-CN/windows-server/identity/ad-ds/plan/reviewing-dns-concepts
For example, we want to access the computer with a bespoke name, we should ensure it located in the right dns name since the Domain Name System is recursively analyzed. 例如,由于要递归分析“域名系统”,因此我们要使用定制名称访问计算机,因此应确保其位于正确的dns名称中。 One more thing I want to share with you is the local “Hosts” file will be used preferentially when the domain name is resolved. 我想与您分享的另一件事是,在解析域名后,将优先使用本地“主机”文件。 Therefore, we could achieve it by add an entry to the file ( located in the System32/drivers/etc/hosts file). 因此,我们可以通过在文件中添加一个条目(位于System32 / drivers / etc / hosts文件中)来实现此目的。 You could refer to the below link. 您可以参考以下链接。
https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/ https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
Feel free to let me know if there is anything I can help with. 请随时告诉我是否有什么我可以帮助的。

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

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