I'm attempting to create a method within my web service that will log IP of each request for each method in the service. I've attempted using the HttpContext, but no matter what I do it returns a null reference exception. I'd like to be able to grab the IP from the request and log it in a SQL database. Here's an example of one of the methods I'm attempting to log.
public GetPL GPL(string code)
{
var db = new TDCDataContext();
var pq = db.PROC_SELECT_GPL(code).ToList();
//a bunch of nonsense
//logging
var ip = HttpContext.Current.Request.UserHostAddress;
var method = GetMethod();
db.PROC_INSERT_Log(ip, code, method, true, null, null);
return stuff;
}
Am I headed in the wrong direction?