0

I have implemented web service i have one call where two parameter is passing. I want to handle the exception if someone do any mistake with parameters.

Like This

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void Test(string mobile, string amount)
{
    //Code
}

I want that it will catch these type condition.

  1. If some one pass only one parameter.
  2. If someone change the name of parameter like mobile to mobile1

my service responding unhandled exception. I want to handle these condition too. Thanks in advance.

Jun Yu
  • 375
  • 1
  • 5
  • 21
Pankaj Mishra
  • 20,197
  • 16
  • 66
  • 103

1 Answers1

0

I suggest that you "overload" the web services methods. Overloading for your example will result in two (2) Test methods; one with two parameters and another with just one parameter. The method with just one parameter would then assign a default value for the second parameter, then that method would call the method with both arguments. This only works if it is acceptable to assign some fixed default value to a parameter when it is not specified in the call.

See also this stackoverflow page on Web Service Methods and Optional Parameters for more information related to this.

Community
  • 1
  • 1
JohnH
  • 1,920
  • 4
  • 25
  • 32