Skip to main content
 首页 » 编程设计

c#之为什么一些 .net 方法创建的 Web 服务不可见

2024年02月01日2552php

我的代码如下:

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 它应该工作。

请您参考如下方法:

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

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