Reputation: 29683
I have a simple webservice
which returns a string
of message as below:
[WebMethod]
public string GetData()
{
return "Here is your response";
}
So just to log details, is it possible to identify from which system the service has been invoked?
Upvotes: 0
Views: 64
Reputation: 5764
You can use HttpContext
by:
string ip = System.Web.HttpContext.Current.Request.UserHostAddress;
And there is more usefull informations.
Upvotes: 1
Reputation: 113
You can get the host address from the OperationContext.Current. The below code would do it.
RemoteEndpointMessageProperty endpoint = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string address = endpoint.Address;
This will work for both self hosted and IIS hosted services. The Address might give a IPV6 address when the network is configured with it. So you may need to resolve using Dns.GetHostEntry(address) to get the IPV4 address.
Upvotes: 0