C# 为什么某些由.net方法创建的Web服务不可见?

C# 为什么某些由.net方法创建的Web服务不可见?,c#,web-services,C#,Web Services,我的代码如下: public class Service : System.Web.Services.WebService { public Service () { } public class event_t { public string place; public int day; public event_t() { } } [WebMethod]

我的代码如下:

public class Service : System.Web.Services.WebService
{
    public Service () {
    }

    public class event_t
    {
        public string place;
        public int day;
        public event_t()
        { 
        }
    }


    [WebMethod]
    event_t getEvent(string sms)
    {
        event_t tmp = new event_t();
        tmp.place = sms;
        tmp.day = 1;
        return tmp;
    }
}

我的问题是:为什么运行getEvent Web方法时它是不可见的? 根据MSDN,
它应该可以工作。

我非常确定您的getEvent方法需要是公共的

[WebMethod]
public event_t getEvent(string sms)
{
    event_t tmp = new event_t();
    tmp.place = sms;
    tmp.day = 1;
    return tmp;
}

我很确定你的getEvent方法必须是公共的

[WebMethod]
public event_t getEvent(string sms)
{
    event_t tmp = new event_t();
    tmp.place = sms;
    tmp.day = 1;
    return tmp;
}

将辅助功能修改器设置为公共

[WebMethod]
public event_t getEvent(string sms)

默认设置为最低可访问性,这解释了为什么您无法看到它。

将可访问性修饰符设置为公共

[WebMethod]
public event_t getEvent(string sms)

默认设置是尽可能少的可访问性,这解释了为什么您无法看到它。

非常感谢!这真是个愚蠢的问题!谢谢!这真是个愚蠢的问题!因为你询问的方法被标记为私有,而其他所有内容都是公共的。因为你询问的方法被标记为私有,而其他所有内容都是公共的。