WCF: How to get Host IP or Server Name
-
I have a WCF service that is hosted via IIS on multiple web servers. I have a logging method that logs the calls to the database and I'd like to log which server the call is executing on. Does anyone know how to get the host server name or IP address that the WCF call is executing on?
-
Answer:
This is what worked for us. Make sure you have a reference to System.ServiceModel. Then implement the following code in your service method: var context = System.ServiceModel.OperationContext.Current; RemoteEndpointMessageProperty property = (RemoteEndpointMessageProperty)context.IncomingMessageProperties[RemoteEndpointMessageProperty.Name]; string externalIP = property.Address;
Kevin Jensen at Stack Overflow Visit the source
Other answers
Dns.GetHostName() is what i use the most.
Darren Kopp
Use Dns.GetHostName(), because it's much better to get the name of the computer than the host IP. Consider the case when your host computer have more than one IP address, has virtual network cards (VMWare).
Tomas Walek
Environment.MachineName does axactly that
VdesmedT
Related Q & A:
- How to get the IP address of the device in WIFI DIRECT?Best solution by Stack Overflow
- How to change server name in apache?Best solution by ehow.com
- What is the host/server name for Yahoo! Mail?Best solution by Yahoo! Answers
- How do i find my incoming server and my outgoing email server name?Best solution by Yahoo! Answers
- How to get my incoming yMail server?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.