passing a class that inherits from BusinessListBase to a web service method

passing a class that inherits from BusinessListBase to a web service method

Old forum URL: forums.lhotka.net/forums/t/286.aspx


idrissb posted on Tuesday, June 06, 2006

I have a windows application that has 2 classes

Class A - Thing inherit from Businessbase

Class B- Things inherit from BusinessListBase

I want to call a web method that passes Class B to the the web method and return Class B to the windows program. It is marked as Serialize() but the proxy is unable to generate the class

Is it possible to pass inherited objects from BusinessListBase to a web methods. any insights will be appreciated.

thanks

idriss

Tim FOrd replied on Tuesday, June 06, 2006

Hi Idriss

Are you getting any errors??

Tim.

idrissb replied on Tuesday, June 06, 2006

no When I create a Web reference in my program and look at the reference.cs, I see it created the thing class but not the THINGS class that was  inerithed from BusinessListBase.

so when I run my program, i get an error at point that about InvalidOperation.

thanks

Tim FOrd replied on Tuesday, June 06, 2006

OK, So let me get this straight.

You have Class A which inherits from BusinessBase
You have Class B which inherits from BusinessListBase(of Class A)

You have a webservice which has a function Something(byval T as Class B) which returns Class B(reference original post)

right?

Tim.

idrissb replied on Tuesday, June 06, 2006

pretty much, yes. here is the code for the webmethod. AreaProjects is Class B

[WebMethod(CacheDuration = 0, MessageName = "UpdateAreaProject", EnableSession = true)]

public StatusData UpdateAreaProject(AreaProjects areaProjects)

{

//AreaProjects areaProjects = new AreaProjects();

StatusData status = new StatusData();

try

{

status = areaProjects.Data_Update();

}

catch (Exception ex)

{

status.StatusID = (int)StatusData.StatusTypeEnum.Error;

status.TechnicalDescription += ex.ToString() + "\r\n";

}

return status;

}

Tim FOrd replied on Tuesday, June 06, 2006

Right i know this is in VB.Net but should be pretty easy to convert.

Have you tried declaring your method like below??

    <WebMethod()> _
    Public Function PassClassA(ByVal listbaseclass As Csla.BusinessListBase(Of CSLAClass.ClassB, CSLAClass.ClassA))

    End Function

Will fire up C# shortly and try and work it out that way you are doing it.


Tim

idrissb replied on Tuesday, June 06, 2006

Tim

thanks for your help. It is not working. For some reason, when the proxy is created it just can not serialize any class derived from BusinessListBase<T,C>. It has no problem serializing classes deriving from BusinessBase<T>

I am at a loss.

Thanks

idriss

RockfordLhotka replied on Tuesday, June 06, 2006

Have you looked at Chapter 11? It specifically covers how to create a web service that returns data based on a business object.

idrissb replied on Sunday, June 11, 2006

Hi, I have purchased the book and read Chapter 11. It does not cover my issue. May be you can shed some light on it. I have also reviewed the source code that comes with the book. I have no problem passing to the web service and sending from the web service any class derived from BusinessBase. Classes deriving from BusinessBase contain on item so passing or receiving one item works fine.
 
so for example
 
public class Project : BusinessBase<Project> contains information for one project
public class Projects : BusinessListBase<Projects, Project>, ISerializable
 
What I want to do is pass a the Projects class that derives from businessListBase which holds a list of projects. That class can not be serialized for some reason. is it because it supports IBindingList. It looks like it creates a Projects[] array in the proxy document but I can't seem to be able to add anything to it.

If you can shed some light, much apprieciated.
 
Idriss




From: cslanet@lhotka.net
To: idrissbennis@hotmail.com
Date: Tue, 6 Jun 2006 17:27:13 -0500
Subject: Re: [CSLA .NET] passing a class that inherits from BusinessListBase to a web service method

Have you looked at Chapter 11? It specifically covers how to create a web service that returns data based on a business object.




Express yourself instantly with MSN Messenger! MSN Messenger

RockfordLhotka replied on Monday, June 12, 2006

As I discuss in Chapter 11, you should not directly return a business object as a result of a web method. Instead, you should create "message objects" either in C# or through an XSD to define the data you are transferring. Chapter 11 does include an example of returning a Project with its associated resource data, and I recommend following that approach.
 
Rocky
 
Rockford Lhotka  (rocky@lhotka.net)
Magenic Technologies Principal Technology Evangelist
Microsoft Regional Director and MVP


From: Idriss Bennis [mailto:cslanet@lhotka.net]
Sent: Sunday, June 11, 2006 3:58 PM
To: rocky@lhotka.net
Subject: RE: Re: [CSLA .NET] passing a class that inherits fromBusinessListBase to a web service method

Hi, I have purchased the book and read Chapter 11. It does not cover my issue. May be you can shed some light on it. I have also reviewed the source code that comes with the book. I have no problem passing to the web service and sending from the web service any class derived from BusinessBase. Classes deriving from BusinessBase contain on item so passing or receiving one item works fine.
 
so for example
 
public class Project : BusinessBase<Project> contains information for one project
public class Projects : BusinessListBase<Projects, Project>, ISerializable
 
What I want to do is pass a the Projects class that derives from businessListBase which holds a list of projects. That class can not be serialized for some reason. is it because it supports IBindingList. It looks like it creates a Projects[] array in the proxy document but I can't seem to be able to add anything to it.

If you can shed some light, much apprieciated.
 
Idriss




From: cslanet@lhotka.net
To: idrissbennis@hotmail.com
Date: Tue, 6 Jun 2006 17:27:13 -0500
Subject: Re: [CSLA .NET] passing a class that inherits from BusinessListBase to a web service method

Have you looked at Chapter 11? It specifically covers how to create a web service that returns data based on a business object.




Express yourself instantly with MSN Messenger! MSN Messenger


Copyright (c) Marimer LLC