Entity must be parameterless?

I am new to write application that connect through internet via web services. I wrote several entities with parametered constructor. But I got the following error when I run through Internet(but not on LAN). Does it means .NET entities that pass by web services must be parameterless

Thanks a lot.

System.ApplicationException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> There was an error generating the XML document. ---> Entity.eWarehouse cannot be serialized because it does not have a parameterless constructor. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at BEInternetAccess.OthersServ.GetWarehouses(String strConn, String strLanguage, Boolean booHasAll) at BLL.Warehouse.GetWarehouses(String strConn, String strWS_URL, String strTypeOfConnection, String strLanguage, Boolean booHasAll) at BLL.Warehouse.GetWarehouses(String strConn, String strWS_URL, String strTypeOfConnection, String strLanguage, Boolean booHasAll) at PSL.Core.FormMain.FormInvoiceView.FormInvoiceView_Load(Object sender, EventArgs e)




Answer this question

Entity must be parameterless?

  • Kinetic Media

    Thanks Vakram. After I added the parameterless constructor, I get the following error: What is wrong Thanks again.

    System.ApplicationException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> There was an error generating the XML document. ---> The type Entity.eWarehouse was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at BEInternetAccess.OthersServ.GetWarehouses(String strConn, String strLanguage, Boolean booHasAll) at BLL.Warehouse.GetWarehouses(String strConn, String strWS_URL, String strTypeOfConnection, String strLanguage, Boolean booHasAll) at BLL.Warehouse.GetWarehouses(String strConn, String strWS_URL, String strTypeOfConnection, String strLanguage, Boolean booHasAll) at Techwave.BizEasy.PSL.Core.FormMain.FormInvoiceView.FormInvoiceView_Load(Object sender, EventArgs e)
    The Entity is simple:
    [Serializable()]
    public class eWarehouse
    {
    private string _strWarehouseName ;
    private int _intWarehouseNo;
    private decimal _decQuantity=0;
    public eWarehouse()
    {
    }
    public eWarehouse(int intWarehouseNo, string strWarehouseName, decimal decQuantity)
    {
    this._strWarehouseName = strWarehouseName;
    this._intWarehouseNo = intWarehouseNo;
    }
    public string WarehouseName
    {
    get { return this._strWarehouseName; }
    set { this._strWarehouseName = value; }
    }
    public int WarehouseNo
    {

    get { return this._intWarehouseNo; }
    set { this._intWarehouseNo = value; }
    }
    public decimal Quantity
    {
    get { return this._decQuantity; }
    set { this._decQuantity = value; }
    }
    }


  • ds12will

    But why

    I hate adding something to my code without understanding it.


  • _Raj_

    Kennon,

    Could you show some of the client-side code, as well as the signature of the server-side method (webmethod) that you're trying to call



  • Rabtok

    Here are the related calls:

    Web Service

        [WebMethod]
        public ArrayList GetWarehouses(string strConn, string strLanguage, bool booHasAll)
        {
                return DAL.dWarehouse.GetWarehouses(strConn, strLanguage, booHasAll);
            throw new ApplicationException("Invalid login.");
        }

    Data Access Layer

      public static ArrayList GetWarehouses(string strConn, string strLanguage, bool booHasAll)
      {
       ArrayList alWarehouse = new ArrayList(5);

       DataSet ds = dDefault.GetDataSetDefaultLikes("WarehouseName", strConn);
      

        alWarehouse.Add(new eWarehouse(0, ds.Tables[0].Rows[0]["PropertyValue"] == null "Wh 0" : ds.Tables[0].Rows[0]["PropertyValue"].ToString(), 0));    alWarehouse.Add(new eWarehouse(1, ds.Tables[0].Rows[1]["PropertyValue"] == null "Wh 1" : ds.Tables[0].Rows[1]["PropertyValue"].ToString(), 0));
                    alWarehouse.Add(new eWarehouse(2, ds.Tables[0].Rows[2]["PropertyValue"] == null "Wh 2" : ds.Tables[0].Rows[2]["PropertyValue"].ToString(), 0));
                    alWarehouse.Add(new eWarehouse(3, ds.Tables[0].Rows[3]["PropertyValue"] == null "Wh 3" : ds.Tables[0].Rows[3]["PropertyValue"].ToString(), 0));
                    alWarehouse.Add(new eWarehouse(4, ds.Tables[0].Rows[4]["PropertyValue"] == null "Wh 4" : ds.Tables[0].Rows[4]["PropertyValue"].ToString(), 0));

       

       return alWarehouse;
      }

     

    CLIENT-SIDE
      public static ArrayList GetWarehouses(string strConn, string strWS_URL, string strTypeOfConnection, string strLanguage, bool booHasAll)
      {
         OthersServ proxy = Common.GetProxy(strWS_URL);

          ArrayList alWarehouse = new ArrayList(5);

          //-------Coz proxy.GetWarehouses return object[] instead of ArrayList, I just put it back to an ArrayList-------
          foreach (object obj in proxy.GetWarehouses(strConn, strLanguage, booHasAll))
           alWarehouse.Add(obj);

          return alWarehouse;
       }

      }

     public class Common
     {
      public Common()
      {
      }

      internal static OthersServ GetProxy(string strWS_URL)
      {
       OthersServ proxy =new OthersServ();
       proxy.Url = strWS_URL+"\\OthersServ.asmx";
       return proxy;
      }
     }

     

    Many many thanks



  • Sean Allison

    Hi,

    For the purpose of serialization it would also need to have the parameterless contructor defined explicitly. Add the paramterless constructor in addition to your parameterized constructors and it should work fine.

    Regards,

    Vikram



  • Doc Glazer

    This thread has been moved to the right location: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=216886&SiteID=1

  • SunilKannan

    Any suggestion is appreciated.

  • Entity must be parameterless?