我試着去的構造函數添加到我的web服務,看起來像這樣:添加一個構造器的Web服務C#
public class ILotusNotesService : System.Web.Services.WebService
{
List<Calendar> cal = new List<Calendar>();
[WebMethod]
public List<Calendar> GetAllCal(string room)
{
DateTime d_start = new DateTime(2012,1,3,12,30,0);
DateTime d_end = new DateTime(2012, 1, 3, 13, 00, 0);
Calendar c1 = new Calendar("Søren Steffensen", "Mødelokale 1", "Privat", d_start, d_end);
DateTime d_start2 = new DateTime(2012, 1, 3, 13, 30, 0);
DateTime d_end2 = new DateTime(2012, 1, 3, 14, 00, 0);
Calendar c2 = new Calendar("Knud Olesen", "Mødelokale 1", "Privat", d_start2, d_end2);
DateTime d_start3 = new DateTime(2012, 1, 3, 15, 30, 0);
DateTime d_end3 = new DateTime(2012, 1, 3, 16, 00, 0);
Calendar c3 = new Calendar("Morten Nielsen", "Mødelokale 1", "Miljø Politik", d_start3, d_end3);
cal.Add(c1);
cal.Add(c2);
cal.Add(c3);
return cal;
}
而且構造看起來像這樣
[DataContract(Name = "Calendar")]
public class Calendar: System.Web.Services.WebService
{
[DataMember(Name = "_meetingHolder")]
public String _meetingHolder { get; set; }
[DataMember(Name = "_meetingRoom")]
public String _meetingRoom { get; set; }
[DataMember(Name = "_status")]
public String _status { get; set; }
[DataMember(Name = "_startTime")]
public DateTime _startTime { get; set; }
[DataMember(Name = "_endTime")]
public DateTime _endTime { get; set; }
public Calendar(string meetingHolder, string MeetingRoom,string status, DateTime startTime, DateTime endTime)
{
this._meetingHolder = meetingHolder;
this._meetingRoom = MeetingRoom;
this._status = status;
this._startTime = startTime;
this._endTime = endTime;
}
}
但我不斷收到這錯誤:
LotusNotesServiveLibrary.Calendar cannot be serialized because it does not have a default public constructor
我試着添加一個空的構造函數。但現在即時獲取此錯誤要成爲XML可序列化,從ICollection繼承的類型必須在其繼承層次結構的所有級別都有一個Add(System.Object)實現。 System.Web.HttpApplicationState不實現添加(System.Object)。 – mortenstarck 2012-01-30 13:06:24