简体   繁体   中英

Connect to WCF service with name instead of IP

Hey I have made an WCF service and would like to be able to connect to it with an dns I set? as it is now I have to conncet to the baseaddress via the computers ip. and the DHCP sometimes gives new ip and then the clients have to know the new ip and so on... you hopefully get it :)

so how can I make it connect via a name instead? and like have localhost in baseaddress

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="metaAndErrors" 
               name="VenatoWCF.WCFService">
        <endpoint address="http://localhost:8732/End"
                  binding="basicHttpBinding"
                  contract="VenatoWCF.IService">
          <identity>
            <dns value="dendei"/>
          </identity>
        </endpoint>
        <endpoint address="http://localhost:8732/mex" 
                  binding="mexHttpBinding" 
                  contract="IMetadataExchange">
          <identity>
            <dns value="dendei"/>
          </identity>
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/VenatoWCFconsole/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metaAndErrors">
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

been trying something like this but no luck xD, i would like to connect from client side with "http://dendei:8732/VenatoWCFconsole/"

so even if my ip changes the clients dont have to make changes to connect to me

thank you for answers!

no matter what, something will have to supply the endpoint address (ie ip/port). If that value is set to change frequently, i would set a port forwarder in between your client and service.

http://en.wikipedia.org/wiki/Port_forwarding

I think this is a scenario that should "just work". Your service base address in the service config should be able to use localhost as you illustrated. In your client-side config you should configure your endpoint address using the DNS name for the host where the service is running.

Check that the client machine can ping the service machine using the DNS name. If that resolves ok, there is no reason why WCF shouldn't connect. You should not have to change any config when the DHCP server decides to allocate a new IP address, so long as clients can still resolve the DNS name to the new IP address.

For example, in your client config...

<client>
  <endpoint address="http://dendei:8732/VenatoWCFconsole/End"
    binding="basicHttpBinding" bindingConfiguration="sameBindingConfigYouAlreadyUse"
    contract="Whatever.YourContractNameIs" name="YourEndpointName" />
</client>

Update: I just spotted there's a problem in your service config above. In the service endpoint config you should specify address as just the additional part of the URI that will get appended to the base-address. So, instead of address="http://localhost:8732/End" , you just need address="End" .

据我了解,您没有静态IP地址,并尝试通过使用静态DNS名称来解决此问题,在我看来,这将不起作用,因为您应该拥有静态IP地址,而不是为其分配静态DNS名称,然后尝试连接。

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