WCF DataContract Error.

Posts   
 
    
Posts: 5
Joined: 12-Apr-2009
# Posted on: 22-May-2009 12:18:27   

Hi, I use llblgen to generate a "ORM" project(llblgen is v2.6 and use adapter), and refers to "WCF" project. Now I want to use entities in "Web" project through "WCF" project, in other words "Web" project will not assemble the ORM.dll. In "Web" project I could'n defind the entity of "ORM" I try to resorve it by adding [DataContract] attribute on entity class. but occur an error: "Type "ORM.EntityClasses.UserEntity' cannot be IXmlSerializable and have DataContractAttribute attribute."

Now I have two questions: 1. Is it right of my way? 2. If yes, how to deal with the error? 3. How to auto generate the [DataContract] and [DataMember] attributes on entity class. 4. If not right, please tell me the way to resorve it?

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 25-May-2009 14:14:15   

It's not clear to me what you have tried and what you haven't.

But in general you should start by checking our WCF project example published in the download section of our website.

There we used a windows client which communictas to a WCF service to get its entities. This shouldn't be any different than using a Web Client.

Please make sure you read the ReadMe.txt file.

Posts: 5
Joined: 12-Apr-2009
# Posted on: 26-May-2009 01:31:17   

Hi Walaa, The point is that I don't want to refer the ORM project in Web client.

For example:

In your WCF demo, you refer the "SD.LLBLGen.Pro.Examples.WCF" in "SD.LLBLGen.Pro.Examples.WCF.Client". This is the problem. I just want to refer the "SD.LLBLGen.Pro.Examples.WCF" in "SD.LLBLGen.Pro.Examples.WCF.Service". And then I can use entity and entity collection via Service, I want to keep a clean Web client. The client doesn't need to refer the "SD.LLBLGen.Pro.Examples.WCF".

Thank you.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-May-2009 07:23:02   

Hi Walter,

I think that's no possible, as WCF service return EntityClasses, your client have to know about how to handle them, so it's necessary to reference the assembly.

If you want to do that, IMHO, you should use DTO's.

David Elizondo | LLBLGen Support Team
Posts: 5
Joined: 12-Apr-2009
# Posted on: 27-May-2009 02:44:59   

OK. But now if I want to add DataContract attribute to generated entity class, how to not occur the error.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-May-2009 10:13:20   

You can't do this, as EntityClasses are not premitiveTypes or known types to the .NET Framework. So you can't decorate it with the dataContract attribute and expects the framework to re-cnstruct these entities at client side.

So in your situation I'd say you should use a DTO. Please search the forums for DTO, and you'll find some templates, and ones which are specific to WCF usage.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 27-May-2009 11:20:13   

DataContract's are also too rigid in most cases, you should use a servicecontract as described in the example.

Frans Bouma | Lead developer LLBLGen Pro