VS2010 Framework 3.5中的Web Service中的方法在本地运行时不显示

aaa*_*son 5 c# asp.net web-services visual-studio-2010

我正在尝试在VS2010中创建一个Web服务,并将其作为3.5 Framework Web Service项目.

我有默认的Hello World方法,还有一些我添加的方法.我添加的那些调用了数据提供程序类,而数据提供程序类又连接到数据集.但是当我在本地运行时,我只看到Hello World方法,而不是我的新方法.然后我删除了hello world方法并重新运行,我仍然看到它.

在本地运行此操作需要做什么,是否与在我的登台和生产服务器上运行它的过程相同?

我习惯于在1.1中创建服务,这是我在3.5中创建的第一个服务.

Dav*_*vid 5

我假设通过"它没有显示"你的意思是当你运行Web服务网站并导航到.asmx页面时,该方法没有显示在可用服务调用列表中,如此屏幕截图所示:

在此输入图像描述

如果这就是你的意思....

很可能您在[WebMethod()]函数定义之前缺少声明,或者该方法未声明为public.

例:

[WebMethod()]
public string GetName(int EmployeeNumber)
{
   // some code to get name from emplyee #
   return ReturnValue;
}
Run Code Online (Sandbox Code Playgroud)

应该在本地运行Web服务项目时显示.

这些都不会:

public string GetName(int EmployeeNumber)
{
   // some code to get name from employee #
   return ReturnValue;
}
Run Code Online (Sandbox Code Playgroud)

要么

[WebMethod()]
private string GetName(int EmployeeNumber)
{
   // some code to get name from employee #
   return ReturnValue;
}
Run Code Online (Sandbox Code Playgroud)

此外,我猜你删除HelloWorld方法时看到你的方法的原因,原因是你只是删除方法并留下[WebMethod()]声明.然后,这将更改代码,以便[WebMethod()]声明应用于您的函数,因为它可能是声明后的第一个函数.