Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. parameterless constructor

parameterless constructor

Scheduled Pinned Locked Moved C#
help
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brsecu
    wrote on last edited by
    #1

    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); } }

    D S 2 Replies Last reply
    0
    • B brsecu

      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); } }

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • B brsecu

        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); } }

        S Offline
        S Offline
        Scott Dorman
        wrote on last edited by
        #3

        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.

        B 1 Reply Last reply
        0
        • D DavidNohejl

          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

          B Offline
          B Offline
          brsecu
          wrote on last edited by
          #4

          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); } } }

          D 1 Reply Last reply
          0
          • S Scott Dorman

            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.

            B Offline
            B Offline
            brsecu
            wrote on last edited by
            #5

            Thanks. I don't know how i missed that. but now i'm getting a new error. WIll you look at it above? Thanks. It seems pretty simple.

            1 Reply Last reply
            0
            • B brsecu

              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); } } }

              D Offline
              D Offline
              DavidNohejl
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups