Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2007

Tip: Looking for answers? Try searching our database.

Newbie: does not have a parameterless constructor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vncntj - 25 Nov 2007 00:07 GMT
I'm working on my first Web Service and need to display data from a
Sql Database.  I get this error message:

"Telemarketing.TUsers cannot be serialized because it does not have a
parameterless constructor."

I have my "proxy ?" content page TUsers.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Telemarketing
{
   public class TUsers
   {

       #region Properties
       private string mReason;
       private string mReid;

       public string Reason
       {
           get
           {
               return mReason;
           }
           set
           {
               mReason = value;
           }
       }

       public string Reid
       {
           get
           {
               return mReid;
           }
           set
           {
               mReid = value;
           }
       }

       #endregion

       #region Methods
       public TUsers(string Reason, string Reid)
       {
           mReason = Reason;
           mReid = Reid;
       }

   }
       #endregion

   public class ListTUsers
        {

            public List<TUsers> TUsers
            {
                get
                {
                    List<TUsers> lst = new List<TUsers>();

                    DataTable dt = GetTUsers().Tables["tno"];
                    foreach (DataRow dr in dt.Rows)
                    {
                        TUsers t = new TUsers(dr["Reason"].ToString(),
dr["Re_id"].ToString());
                        lst.Add(t);
                    }
                    return lst;
                }
            }

            internal DataSet GetTUsers()
            {
                string SQL = "Select Reason, Re_id From tno";
                SqlDataAdapter da = new SqlDataAdapter(SQL, Conn.ConnString);
                DataSet ds = new DataSet();
                da.Fill(ds, "tno");
                return ds;
            }
        }
}

and the BlogService.cs codebehind page for BlogService.asmx

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using Telemarketing;

/// <summary>
/// Summary description for BlogService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class BlogService : System.Web.Services.WebService {

   public BlogService () {

       //Uncomment the following line if using designed components
       //InitializeComponent();
   }

   [WebMethod()]
   public List<Telemarketing.TUsers> ListTUsers()
   {
       ListTUsers lt = new ListTUsers();
       return lt.TUsers;

   }
}

Thanks
Dave Bush - 25 Nov 2007 00:38 GMT
What part of the message don't you understand?  Parameterless?  Or
Constructor?

-----Original Message-----
From: vncntj [mailto:vncntj@hotmail.com]
Posted At: Saturday, November 24, 2007 7:08 PM
Posted To: microsoft.public.dotnet.framework.aspnet.webservices
Conversation: Newbie: does not have a parameterless constructor
Subject: Newbie: does not have a parameterless constructor

I'm working on my first Web Service and need to display data from a
Sql Database.  I get this error message:

"Telemarketing.TUsers cannot be serialized because it does not have a
parameterless constructor."

I have my "proxy ?" content page TUsers.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Telemarketing
{
   public class TUsers
   {

       #region Properties
       private string mReason;
       private string mReid;

       public string Reason
       {
           get
           {
               return mReason;
           }
           set
           {
               mReason = value;
           }
       }

       public string Reid
       {
           get
           {
               return mReid;
           }
           set
           {
               mReid = value;
           }
       }

       #endregion

       #region Methods
       public TUsers(string Reason, string Reid)
       {
           mReason = Reason;
           mReid = Reid;
       }

   }
       #endregion

   public class ListTUsers
        {

            public List<TUsers> TUsers
            {
                get
                {
                    List<TUsers> lst = new
List<TUsers>();

                    DataTable dt =
GetTUsers().Tables["tno"];
                    foreach (DataRow dr in dt.Rows)
                    {
                        TUsers t = new
TUsers(dr["Reason"].ToString(),
dr["Re_id"].ToString());
                        lst.Add(t);
                    }
                    return lst;
                }
            }

            internal DataSet GetTUsers()
            {
                string SQL = "Select Reason, Re_id From
tno";
                SqlDataAdapter da = new
SqlDataAdapter(SQL, Conn.ConnString);
                DataSet ds = new DataSet();
                da.Fill(ds, "tno");
                return ds;
            }
        }
}

and the BlogService.cs codebehind page for BlogService.asmx

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using Telemarketing;

/// <summary>
/// Summary description for BlogService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class BlogService : System.Web.Services.WebService {

   public BlogService () {

       //Uncomment the following line if using designed components
       //InitializeComponent();
   }

   [WebMethod()]
   public List<Telemarketing.TUsers> ListTUsers()
   {
       ListTUsers lt = new ListTUsers();
       return lt.TUsers;

   }
}

Thanks
vncntj - 25 Nov 2007 01:14 GMT
I figured it out.
Thanks.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.