How to use static function in web service?

  • Thread starter Thread starter Mark Ingram
  • Start date Start date
M

Mark Ingram

Hi, how can I use a static function in a web service from a C# app?

I have the following code in a web service:

public class MyClass
{
[WebMethod]
public static Boolean Exists(String check)
{
return false;
}
}



Then in the C# app I try to use the web service:

MyClass.Exists("");

And I get an error saying Exists doesn't exist.



Can you not use static functions? Or am I doing something wrong?

Thanks
 
You can only apply [System.Web.Services.WebMethod()] attaribute to non static
methods, however you may use static members within webmethod i.e.

public class MyClass
{
[WebMethod]
public bool Exists(String check)
{
return InternalExists(check);
}

private static bool InternalExists(string check)
{
// TODO : implement
return false;
}


}

hope this helps
 
Back
Top