Error when returning xml from webservice

Posts   
 
    
tbelknap
User
Posts: 36
Joined: 28-Jun-2006
# Posted on: 03-Jan-2007 06:04:22   

Hello again,

I have a OwnerEntity that has one to many properties. I am return a collection of ownerentities including the properties from a webservice using writexml.

I am reading on the client side using readxml and getting the following error.

System.ArgumentException: Object of type 'CREToolkit.data.EntityClasses.OwnerEntity' cannot be converted to type 'CREToolkit.data.EntityClasses.MyOwnerEntity'. at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value) at SD.LLBLGen.Pro.ORMSupportClasses.XmlHelper.SetReadReferences(List1 nodeEntityReferences, Dictionary2 processedObjectIDs) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase21.ReadXml(XmlNode node) at SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase21.ReadXml(String xmlData) at CreToolkit.UIWebSellers.LoadWorker_DoWork(Object sender, DoWorkEventArgs e) in C:\Documents and Settings\Thomas Belknap\My Documents\Visual Studio 2005\Projects\CreToolkit\UserControls\Websites\UIWebSellers.vb:line 215

I know this has something to do with the properties being included. I tested just returning the ownerentities without the properties and it worked.

Thanks,

Thomas

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Jan-2007 08:48:03   

Please post more info: 1- RuntimeLibrary version? 2- Post the code of the webService that performs the WriteXML, and the code at the client that performs the ReadXML.

Make sure the server and client apps are using the same version of the generated assemblies/code.

Note: generics(EntityCollection<OwnerEntity>) aren't supported in webservices nor are polymorphic fetches. This means that the type returned by the webmethod is the type of object you will get on the client. If you return an instance of a derived type of the webmethod's returntype (e.g. you return a ManagerEntity while the method's returntype is EmployeeEntity, you'll get an EmployeeEntity object at the client, not a ManagerEntity object.

tbelknap
User
Posts: 36
Joined: 28-Jun-2006
# Posted on: 03-Jan-2007 09:27:55   

Runtime v2.0.50727

I am getting the correct entity that I want.

OwnerEntity has many PropertyEntity. I am prefetching my PropertyEntityCollection when I get my OwnerEntityCollection on the webservice.

I write the xml from the OwnerEntity Collection on the webservice.

On the client I have a collection of OwnerEntity type. I read in the xml there and that is where i get the casting error.

When I stopped prefetching the PropertyEntityCollection on the webservice and just returned the OwnerEntityCollection everything worked.

It has something to do with my prefetch. Here is the code for that.

        Dim Sellers As New EntityCollection(Of OwnerEntity)

        Dim Prefetch As IPrefetchPath2 = New PrefetchPath2(CInt(EntityType.OwnerEntity))
        Prefetch.Add(OwnerEntity.PrefetchPathPropertyLead)

        Using adapter As New DataAccessAdapter
            adapter.ConnectionString = Connection
            adapter.FetchEntityCollection(Sellers, Nothing, Prefetch)
            adapter.CloseConnection()
        End Using

        Prefetch = Nothing

        Return Sellers

It works when I take out the prefetch.

Thomas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 03-Jan-2007 10:26:36   

Please rightclick the ORMSupportClasses dll in windows explorer -> properties -> Version tab, that's the version, e.g. 2.0.0.061205

Also, it seems you're using adapter with derived entities, be sure to use these on BOTH sides.

Frans Bouma | Lead developer LLBLGen Pro
tbelknap
User
Posts: 36
Joined: 28-Jun-2006
# Posted on: 03-Jan-2007 10:50:38   

Otis wrote:

Please rightclick the ORMSupportClasses dll in windows explorer -> properties -> Version tab, that's the version, e.g. 2.0.0.061205

Also, it seems you're using adapter with derived entities, be sure to use these on BOTH sides.

2.0.0.061023

I think that is the problem. I don't think I set up the entitycollection correctly on my client.

I am not sure how to set it up to allow me to read in the derived entities from xml.

Right now it is only a EntityCollection(of OwnerEntity)

What do I need to do to set it up to allow for my propertycollection?

Thomas

tbelknap
User
Posts: 36
Joined: 28-Jun-2006
# Posted on: 04-Jan-2007 02:43:50   

Any ideas on how I should be creating my EntityCollection on the client to allow for my derived entities?

Thomas

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 04-Jan-2007 07:24:21   

System.ArgumentException: Object of type 'CREToolkit.data.EntityClasses.OwnerEntity' cannot be converted to type 'CREToolkit.data.EntityClasses.MyOwnerEntity'.

Did you make sure you are using the same version of the generated code on both sides (server & client)? Does both sides have MyOwnerEntity defined?

2- Post the code of the webService that performs the WriteXML, and the code at the client that performs the ReadXML.

Please

tbelknap
User
Posts: 36
Joined: 28-Jun-2006
# Posted on: 04-Jan-2007 07:42:21   

Yes, same version on both the client and server.

Server code:

    Dim sellerXml As String = String.Empty

    Dim Sellers As EntityCollection(Of OwnerEntity) = TigerBuyingWebsite.GetSellers(Setting.GetConnection)

    If Not Sellers Is Nothing Then

        Sellers.WriteXml(XmlFormatAspect.Compact, sellerXml)
        Return sellerXml

    Else

        Return ""

    End If

Client Code:

        Sellers.Clear()
        Sellers = New EntityCollection(Of OwnerEntity)
        Sellers.ReadXml(WebService.GetSellers)

Thanks,

Thomas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 04-Jan-2007 11:03:06   

As you use derived entities, you have to use: Prefetch.Add(MyOwnerEntity.PrefetchPathPropertyLead)

instead. Otherwise it uses the OwnerEntity's prefetch path and inserts the PropertyLeadEntity's factory instead of the MyPropertyLeadEntity's factory.

Frans Bouma | Lead developer LLBLGen Pro
tbelknap
User
Posts: 36
Joined: 28-Jun-2006
# Posted on: 05-Jan-2007 15:14:05   

This is what I am using on the server side now.

        Dim Sellers As New EntityCollection(Of OwnerEntity)

        Dim Prefetch As IPrefetchPath2 = New PrefetchPath2(CInt(EntityType.OwnerEntity))
        Prefetch.Add(MyOwnerEntity.PrefetchPathPropertyLead)

        Using adapter As New DataAccessAdapter
            adapter.ConnectionString = Connection
            adapter.FetchEntityCollection(Sellers, Nothing, Prefetch)
            adapter.CloseConnection()
        End Using

        Prefetch = Nothing

        Return Sellers

I am still getting the same error. Do I need to do anything with my client side code to allow for the PropertyLeadCollection?

Thomas

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 05-Jan-2007 15:18:04   

I think I see what's the problem. You also need to do: Dim Sellers As New EntityCollection(Of MyOwnerEntity)

Or better: Dim Sellers As New EntityCollection(Of MyOwnerEntity)(New MyOwnerEntityFactory())

as the error comes from the fact that the PropertyLead.Owner property is set to an Owner instance (as you specified 'OwnerEntity') but the MyPropertyLead class has that property defined as a property of the type MyOwnerEntity.

Frans Bouma | Lead developer LLBLGen Pro