Reputation: 69
I am trying to create a web service in VS2010 and doing it as a 3.5 Framework Web Service project.
I have the default Hello World method in there and some that I have added. The ones I have added have a call to a data provider class that in turn connects to the dataset. However when I run locally I only see the Hello World method and not my new methods. I then delete the hello world method and rerun and I still see it.
What do I need to do to run this locally and is it the same process as to have it run on my staging and production servers?
I am used to creating services in 1.1 and this is my first one I am creating in 3.5.
Upvotes: 5
Views: 1598
Reputation: 31237
Check if your function is declared static or not? So even [WebMethod()] in the following situation will not work:
[WebMethod()]
public static string GetName(int EmployeeNumber)
{
// some code to get name from employee #
return ReturnValue;
}
Remove static and it will work!!
Upvotes: 0
Reputation: 73564
I'm assuming that by "It's not showing up" you mean that when you run the web services website and navigate to the .asmx page the method isn't showing up in the list of available service calls as shown in this screenshot:
IF that's what you mean....
Most likely you're either missing the [WebMethod()]
declaration just before the function definition, or the method is not declared as public.
Example:
[WebMethod()]
public string GetName(int EmployeeNumber)
{
// some code to get name from emplyee #
return ReturnValue;
}
should show up when you run the web service project locally.
Neither of these would:
public string GetName(int EmployeeNumber)
{
// some code to get name from employee #
return ReturnValue;
}
or
[WebMethod()]
private string GetName(int EmployeeNumber)
{
// some code to get name from employee #
return ReturnValue;
}
Further, I'm guessing that the reason that you see your method when you delete the HelloWorld method, the reason is that you are deleting just the method and leaving the [WebMethod()]
declaration. This would then change the code so that the [WebMethod()]
declaration is being applied to your function, as it's probably the first function after the declaration.
Upvotes: 5