parameterless constructor
-
I dont know why this is so hard. I just cant get it to work!!! I've tried a million things and different ways. I get this error: WebService1.Class1 cannot be serialized because it does not have a parameterless constructor. public class Class1 : System.Web.Services.WebService { public string _strOne; public string _strTwo; public Class1(string strOne, string strTwo) { this._strOne = strOne; this._strTwo = strTwo; } [WebMethod] public Class1 HelloWorld(string str1, string str2) { return new Class1(str1,str2); } }
-
I dont know why this is so hard. I just cant get it to work!!! I've tried a million things and different ways. I get this error: WebService1.Class1 cannot be serialized because it does not have a parameterless constructor. public class Class1 : System.Web.Services.WebService { public string _strOne; public string _strTwo; public Class1(string strOne, string strTwo) { this._strOne = strOne; this._strTwo = strTwo; } [WebMethod] public Class1 HelloWorld(string str1, string str2) { return new Class1(str1,str2); } }
brsecu wrote:
I get this error: WebService1.Class1 cannot be serialized because it does not have a parameterless constructor.
So have you tried to add parameterless constructor?
public Class1() { }
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
-
I dont know why this is so hard. I just cant get it to work!!! I've tried a million things and different ways. I get this error: WebService1.Class1 cannot be serialized because it does not have a parameterless constructor. public class Class1 : System.Web.Services.WebService { public string _strOne; public string _strTwo; public Class1(string strOne, string strTwo) { this._strOne = strOne; this._strTwo = strTwo; } [WebMethod] public Class1 HelloWorld(string str1, string str2) { return new Class1(str1,str2); } }
Have you tried adding the constructor?
public Class1()
{
}Types can't be serialized if they don't have a default (parameterless) constructor.
----------------------------- In just two days, tomorrow will be yesterday.
-
brsecu wrote:
I get this error: WebService1.Class1 cannot be serialized because it does not have a parameterless constructor.
So have you tried to add parameterless constructor?
public Class1() { }
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
Yeah. Now i get this error. System.NotSupportedException: Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface. Here is my code. Ughhhhhhhhhhh namespace WebService1 { /// /// Summary description for Class1 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class Class1 : System.Web.Services.WebService { public string _strOne; public string _strTwo; public Class1() { } public Class1(string strOne, string strTwo) { this._strOne = strOne; this._strTwo = strTwo; } [WebMethod] public Class1 HelloWorld(string str1, string str2) { str1 = "1"; str2 = "2"; return new Class1(str1, str2); } } }
-
Have you tried adding the constructor?
public Class1()
{
}Types can't be serialized if they don't have a default (parameterless) constructor.
----------------------------- In just two days, tomorrow will be yesterday.
-
Yeah. Now i get this error. System.NotSupportedException: Cannot serialize member System.ComponentModel.MarshalByValueComponent.Site of type System.ComponentModel.ISite because it is an interface. Here is my code. Ughhhhhhhhhhh namespace WebService1 { /// /// Summary description for Class1 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class Class1 : System.Web.Services.WebService { public string _strOne; public string _strTwo; public Class1() { } public Class1(string strOne, string strTwo) { this._strOne = strOne; this._strTwo = strTwo; } [WebMethod] public Class1 HelloWorld(string str1, string str2) { str1 = "1"; str2 = "2"; return new Class1(str1, str2); } } }
See http://msdn2.microsoft.com/en-us/library/system.web.services.webservice.aspx[^]. Looks like workaround is to not derive from
WebService
.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe