How can I determine which WebMethod was called in a web service

The situation is as follows. I have an asp.net webservice application ... let's say the api.asmx page

In the code behind, I have several methods, for example:

[WebMethod(Description="Method1")]
public int GetSomething(int num1, int num2){
  try{
    return SomeObject.DatabaseCall.DoSomething(num1, num2);
  }
  catch(Exception ex){
    object[] pars = new object[] { num1, num2 };
    LogError("GetSomething", pars, ex);
  }
}

[WebMethod(Description="Method2")]
public int GetSomething2(string w, string j, int f){
  try{
    return AnotherObject.DoSomething(w, j, f);
  }
  catch(Exception ex){
    object[] pars = new object[] { w, j, f };
    LogError("GetSomething2", pars, ex);
  }
}

Of course, these are just two simple examples, where, if an exception is thrown, I can register the method call and the parameters passed.

Is there any other way to do this? Is there a way I can extract the called method and / or parameters. I guess I hope someone tells me that I can just have some kind of function like:

LogError(ex);

Server Environment, . , - CurrentContext.WebServiceCall.Magic... try/catch, .

, .

+3
3

Application_Error Global.asax. Server.GetLastError(), Exception.

. Request, , .

+2

StackTrace. .

+1

Your LogError method may call Environment.StackTrace . Then he would “know” which method called it.

0
source

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


All Articles