2013-05-13 27 views
1

我的代码如下:为什么一些由.net方法创建的Web服务不可见?

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 ,http://msdn.microsoft.com/en-us/library/3003scdt(v=vs.71).aspx 它应该工作。

+0

因为你询问的方法被标记为“私人”,其他一切都是“公共”。 – 2013-05-13 16:36:27

回答

5

我很确定你的getEvent方法需要公开。

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

非常感谢!这真是一个愚蠢的问题! – zsf222 2013-05-13 16:14:52

0

设置可访问修饰符公共

[WebMethod] 
public event_t getEvent(string sms) 

默认为最小可达可能这也解释了为什么你不能看到它。

相关问题