locked
Exception thrown: 'System.Net.WebException' in System.dll The remote name could not be resolved: RRS feed

  • Question

  • User-700966645 posted

    I have a WCF Service hosted in IIS on a Windows 10 IoT Enterprise machine on a private network (no domain). When i make calls to my service from the client it is unable to resolve my computer name as it is on my companies domain. Is there a way to tell WCF to use the ip of the incoming request? Using the local hosts file is a non starter.

    Currently site binding are IP: *, Host Name: "", Port:80.

    Service Model Config:

    <system.serviceModel>
        <protocolMapping>
          <remove scheme="http" />
          <add scheme="http" binding="wsDualHttpBinding" bindingConfiguration="CamWindowBinding"/>
          <remove scheme="net.tcp" />
        </protocolMapping>
        <services>
          <service name="CompanyName.EIVisionServer">
            <endpoint address="&quot;&quot;" binding="wsDualHttpBinding"
              bindingConfiguration="CamWindowBinding" name="EICamWindowEndpoint"
              contract="CompanyName.Vision.Services.IEICamWindowContract" />
            <endpoint address="&quot;&quot;" binding="wsDualHttpBinding"
              bindingConfiguration="CamWindowBinding" name="CC24Endpoint"
              contract="CompanyName.Vision.Services.ICC24ServiceContract" />
            <host>
              <baseAddresses>
                <add baseAddress="http://192.168.1.200/EIVisionServer/" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <bindings>
          <wsDualHttpBinding>
            <binding name="CamWindowBinding" receiveTimeout="24.20:31:23.6470000"
              maxReceivedMessageSize="2147483647" messageEncoding="Mtom">
              <readerQuotas maxArrayLength="2147483647" />
              <reliableSession inactivityTimeout="24.20:31:23.6470000" />
              <security mode="None">
                <message clientCredentialType="None" />
              </security>
            </binding>
          </wsDualHttpBinding>
        </bindings>
    	<client>
       <endpoint address="http://192.168.1.200/EIVisionServer.svc" binding="wsDualHttpBinding"
         bindingConfiguration="CamWindowBinding" contract="CompanyName.Vision.Services.IEICamWindowContract"
         name="EICamWindowEndpoint" />
       <endpoint address="http://192.168.1.200/EIVisionServer.svc" binding="wsDualHttpBinding"
         bindingConfiguration="CamWindowBinding" contract="CompanyName.Vision.Services.ICC24ServiceContract"
         name="CC24Endpoint" />
     </client>
        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <useRequestHeadersForMetadataAddress>
                <defaultPorts>
                  <add scheme="http" port="80" />
                </defaultPorts>
              </useRequestHeadersForMetadataAddress>
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>

    Thanks,

    Ryan

    Thursday, June 14, 2018 6:31 PM

Answers

  • User-700966645 posted

    No local dns or hosts file editing required, thanks for all the suggestions though

    Binding.ClientBaseAddress = "http://192.168.x.x:8000" //set to your local client IP

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2018 5:28 PM

All replies

  • User1120430333 posted

    What's wrong with using the LAN IP of the of the machine hosting the service, which would be done from the client machine  hosting the WCF client using an endpoint?  There is no way that I know about that a  WCF service is going to pick out an IP in the network traffic that I know about.

    What does a host file have to do with this?

    Friday, June 15, 2018 3:42 AM
  • User-700966645 posted

    I am referencing the service from the client using the IP, note the client endpoint settings in the servicemodel config. The issue is that the service cannot resolve mycomputer.mycompany.com to an IP to respond to me as it's not on the domain. WRT to host file, adding an entry in the servers hosts file would allow the name to be resolved. 

    Thanks

    Ryan

    Friday, June 15, 2018 3:57 AM
  • User1120430333 posted

    I am referencing the service from the client using the IP, note the client endpoint settings in the servicemodel config. The issue is that the service cannot resolve mycomputer.mycompany.com to an IP to respond to me as it's not on the domain. WRT to host file, adding an entry in the servers hosts file would allow the name to be resolved. 

    Thanks

    Ryan

    The service shouldn't be doing anything with an IP on its end. It is the client machine running the client software that must know the IP of the machine hosting the service with the client making the initial contact with the service on the inbound port the service is listening on  in order for communications between the client and service to commence.  It is the client that must know the IP

    A DNS server on the network equates a domain name to an IP. The service has nothing to do with it.  

    Friday, June 15, 2018 4:34 AM
  • User-700966645 posted
    Maybe I wasn't clear as to where the exception is occurring, the client can make calls to the server. I attach a remote debug session to w3wp and I get the exception in the title. It occurs when the server tries to complete the call it can't resolve my pc ip. If I add an entry to the hosts file the service then can complete the call and the application works as expected.
    Friday, June 15, 2018 6:03 AM
  • User36583972 posted


    Hi gt1485a

    The information about the client ip is passed with the request. If you're receiving the request then you're receiving the ip information being passed by the client.

    If your client IP is on the same network you should be able to get the IP. But if it's not it's important to remember how internet routing and network address tables (NAT) work.

    In larger corporate networks this can be further obfuscated as they could have multiple levels of NATs between you and your client.

    If I add an entry to the hosts file the service then can complete the call and the application works as expected.

    At the moment. This may be the right way for you.

    Best Regards,

    Yong Lu

    Friday, June 15, 2018 8:53 AM
  • User1120430333 posted

    Maybe I wasn't clear as to where the exception is occurring, the client can make calls to the server. I attach a remote debug session to w3wp and I get the exception in the title. It occurs when the server tries to complete the call it can't resolve my pc ip. If I add an entry to the hosts file the service then can complete the call and the application works as expected.

    The  return IP along with the send to  IP were in the network traffic packets that were sent by the client machine the O/S. The service doesn't know about this. It's  at the machine level the O/S(s) on both sides know where to send and receive the packets.

    The fact that you used the host file, an O/S file, is an indication that the packets made it back to the client's machine. The only thing you could have done is mapped the hostname to an IP the machine is using  to complete the route.  The WCF client and service are not the issue as to why you have to do something with the host file on the client computer in order to complete the route.

    You have some kind of networking issue. You are not telling me that you did something on the server machine with the host file, right?  It's on the client machine that you are doing something with the host file, right?

    Friday, June 15, 2018 9:17 AM
  • User753101303 posted

    Hi,

    It seems it would be  better to just fix the name resolution issue ? Ask maybe to the network admin in your company to register the proper DNS name. Ah the service is on your own machine ? This for testing or for production ??? I usually test all on my own machine and then have a valid test or qa or prod config that works without depending on my own machine.

    Friday, June 15, 2018 9:25 AM
  • User-700966645 posted

    The host file change is on the server. This is a config for production. These systems will be on a factory floor and I or someone else from my company may have to debug them and shouldn't have to be added to the servers host file. If the wcf client includes the client pc name instead of ip how do I make it use the ip?
    Friday, June 15, 2018 2:08 PM
  • User1120430333 posted


    The host file change is on the server. This is a config for production. These systems will be on a factory floor and I or someone else from my company may have to debug them and shouldn't have to be added to the servers host file. If the wcf client includes the client pc name instead of ip how do I make it use the ip?

    Have you talked with a network person, becuase you shouldn't have to do anything with the host file? 

    Friday, June 15, 2018 2:37 PM
  • User-700966645 posted

    Here's a network diagram, maybe this will help. The server is in static IP land and debug/dev client is a part of a domain. How do i force the domain client to send it's IP?

    Network Architecture

    Friday, June 15, 2018 4:34 PM
  • User1120430333 posted

    You're talking Windows 10, Hell, I can't get two Windows 10 pro machines to see each other and share resources on a simple LAN using a router. :) It works for a while,  and then the machines can't see each other on the same LAN!

    Friday, June 15, 2018 8:15 PM
  • User-700966645 posted

    Digging further based on your advice I found that on the client side of my WCF call the inner channel is set to my computer name. I've investigated ServicePointManager, BindIPEndPointDelegate and DuplexChannelFactory  but can't find anyway to change the InnerChannel.LocalAddress before the Client/Channel is created. 

    Saturday, June 16, 2018 1:00 AM
  • User1120430333 posted

    Put a Windows 7 machine there and see what happens.

    Saturday, June 16, 2018 1:36 AM
  • User-700966645 posted

    Seems that a Win7 machine behaves the same way. :(

    Thursday, June 28, 2018 7:46 PM
  • User753101303 posted

    Each external square is a subnet ? I believe 192.168.x.x is not routable and shouldn't be able to leave the subnet. Do you have anything that works between the WCF client and the WCF server (for example you can access to a server side HTML page using a browser ?)

    Edit: if you never had any communication between the WCF client and the WCF server then  it's likely how the network is currently designed ie you have a production isolated network ?

    Thursday, June 28, 2018 8:34 PM
  • User-700966645 posted

    Reading this article on netbios I seem to have 2 options: 

    1.  Intercept the remote pc name on connection to the service (context.channel.remoteaddress). Use the computer name to do a System.DNS.GetHostEntry("pcname") returning the IP. Add this to the LMHosts file with the pcname.domain.com form.
    2. Add a local DNS server to intercept the request and resolve the ip like above using GetHostEntry.
    Thursday, June 28, 2018 11:30 PM
  • User-700966645 posted

    @PatrickSc No this is all on the same subnet. It's just that the pc has one nic on the domain and one on the local isolated subnet.

    Thursday, June 28, 2018 11:32 PM
  • User1120430333 posted

    @PatrickSc No this is all on the same subnet. It's just that the pc has one nic on the domain and one on the local isolated subnet.

    You have a machine with two NIC(s)? And you are not disabling one NIC while the other on is in use?  I can see this being a problem. You may not think it's a problem. Maybe, you should try one nic (disable one) at a time to see of the problem goes away. 

    Friday, June 29, 2018 5:03 AM
  • User-700966645 posted

    You have a machine with two NIC(s)? And you are not disabling one NIC while the other on is in use?  I can see this being a problem. You may not think it's a problem. Maybe, you should try one nic (disable one) at a time to see of the problem goes away.

    You are correct I think it shouldn't be a problem, we use machines with multiple NICS all the time, just not with WCF. Wouldn't a pc have a NIC per connection; i.e. wireless + hardline?

    Regardless, disabling the domain NIC does not cause the client to send it's IP. It still sends it's fully qualified domain name because it's a pc registered to a domain? It seems the inability to change the address sent when the client ChannelFactory is called is an oversight in WCF. 

    Friday, June 29, 2018 4:00 PM
  • User1120430333 posted

    You are correct I think it shouldn't be a problem, we use machines with multiple NICS all the time, just not with WCF. Wouldn't a pc have a NIC per connection; i.e. wireless + hardline?

    It's kind of obvious to me that it doesn't apply when WCF is in play here.

    Tuesday, July 3, 2018 8:37 AM
  • User-700966645 posted

    No local dns or hosts file editing required, thanks for all the suggestions though

    Binding.ClientBaseAddress = "http://192.168.x.x:8000" //set to your local client IP

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2018 5:28 PM
  • User1120430333 posted

    No local dns or hosts file editing required, thanks for all the suggestions though

    Binding.ClientBaseAddress = "http://192.168.x.x:8000" //set to your local client IP

    Why are posting the 192.168.x.x? Even if you posted all  the numbers of the IP, no one could use it to do anything since a LAN IP. :)

    Saturday, July 7, 2018 7:41 PM
  • User-700966645 posted

    Why are posting the 192.168.x.x? Even if you posted all  the numbers of the IP, no one could use it to do anything since a LAN IP. :)

    So that it's clear it's an example ....

    Tuesday, July 10, 2018 3:15 PM