How can a service know the caller?

I have a WCF service. How do I know if a call is made by my service on a local computer or machine from a network?

Thanks Adrya

+3
source share
2 answers

You can check the caller's IP. If it is from a local machine, it should be "127.0.0.1". You can get the caller's IP address (remote address) from the OperationContext object. More details here: http://www.danrigsby.com/blog/index.php/2008/05/21/get-the-clients-address-in-wcf/

+4
source

I would compile the list when running ALL known IPs on the local machine using something like ....

 NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
 List<string> addressList = new List<string>();
 foreach (NetworkInterface ni in nis)
 {
      IPInterfaceProperties iip = ni.GetIPProperties();
      UnicastIPAddressInformationCollection unis = iip.UnicastAddresses;
      foreach (UnicastIPAddressInformation uni in unis)
      {
          string address = uni.Address.ToString();
          addressList.Add(address);
      }
 }

List, , IP- 'remote'. , , IP-, 127.0.0.1.

+1

Source: https://habr.com/ru/post/1765981/


All Articles