Is ExcludeIncludeFieldsList Serializable

Posts   
 
    
samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 26-Feb-2010 21:06:20   

I am using WCF and I call my LLBLGen code in WCF. When I call my web service which return the entity collection I want to specify the fields which need to include. So I added a parameter of type ExcludeIncludeFieldsList in the WCF service and when I call the service from my asp.net web page I am passing the ExcludeIncludeFieldsList. But I am getting an error as below

The InnerException message was 'Type 'System.RuntimeType' with data contract name 'RuntimeType:[http://schemas.datacontract.org/2004/07/System](http://schemas.datacontract.org/2004/07/System)' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.

I added [ServiceKnownType(typeof(ExcludeIncludeFieldsList))] to my WCF interface even though I am getting this error. Any idea or work around?

Thanks Sam

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Feb-2010 19:12:32   

Please post: - Exact exception message and stack trace - LLBLGen runtime library version (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7722) - Code snippet of you contract, also, attach (if possible) you .config file

David Elizondo | LLBLGen Support Team
samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 01-Mar-2010 16:18:38   

Exception

An exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll but was not handled in user code

Additional information: There was an error while trying to serialize parameter httpdisappointed /<url>/:includeFields. The InnerException message was 'Type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' with data contract name 'EntityField2:[http://schemas.datacontract.org/2004/07/SD.LLBLGen.Pro.ORMSupportClasses](http://schemas.datacontract.org/2004/07/SD.LLBLGen.Pro.ORMSupportClasses)' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

Code:

code in service Interface

[ServiceKnownType(typeof(IEntityCollection2))] [ServiceKnownType(typeof(ExcludeIncludeFieldsList))]

[OperationContract] IEntityCollection2 getFac(string facId, ExcludeIncludeFieldsList includeFields);

Code in service

public IEntityCollection2 getFac(string facId, ExcludeIncludeFieldsList includeFields) { EntityCollection results = new EntityCollection(new FacVwEntityFactory()); RelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.PredicateExpression.Add(FacVwFields.Status == "ACTIVE"); bucket.PredicateExpression.Add(FacVwFields.FacId == facId);

        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            adapter.FetchEntityCollection(results,includeFields, bucket);

        }
        return results;
    }

code in .aspx

protected void bindFac(string facId) { ChannelFactory<IFacService> facFactory = new ChannelFactory<IFacService>("facService"); IFacService facServer = facFactory.CreateChannel(); using (facServer as IDisposable) { ExcludeIncludeFieldsList includeFields = new ExcludeIncludeFieldsList(); includeFields.ExcludeContainedFields = false; includeFields.Add(FacVwFields.MessageId); includeFields.Add(FacVwFields.Message);

            EntityCollection facCollection = (EntityCollection)facServer .getFac(facID, includeFields);
            RadGrid facGrid = (RadGrid)RadPanelBar1.FindItemByValue("PanelItem1").FindControl("RadGridFac");
            facGrid .DataSource = facCollection ;
            facGrid .DataBind();
        }
    }

I start getting error when I try to pass the ExcludeIncludeFieldsList as the parameter.

I am using the 2.6 Final version of LLBLGen Pro.

Please let me know if you need any further information.

thanks Sam

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 01-Mar-2010 17:11:31   

Please try to pass IEntityField2[] or IEntityFieldCore[] instead. And don't forget to include the corresponding ServiceKNownType attribute.

Then inside the service method, you can loop the array to add fields to an ExcludeIncludeFieldsList instance.

samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 01-Mar-2010 18:02:05   

I used IEntityField2[] and now getting the below exception

An exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll but was not handled in user code

Additional information: There was an error while trying to serialize parameter httpdisappointed /<ur>/:includeFields. The InnerException message was 'Type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' with data contract name 'EntityField2:[http://schemas.datacontract.org/2004/07/SD.LLBLGen.Pro.ORMSupportClasses](http://schemas.datacontract.org/2004/07/SD.LLBLGen.Pro.ORMSupportClasses)' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

the new code is

Service Interface code

[ServiceKnownType(typeof(IEntityField2[]))]

[OperationContract] IEntityCollection2 getFac(string facId, IEntityField2[] includeFields);

Service code

public IEntityCollection2 getFa(string facId, IEntityField2[] includeFields) { EntityCollection results = new EntityCollection(new FacVwEntityFactory()); RelationPredicateBucket bucket = new RelationPredicateBucket(); bucket.PredicateExpression.Add(FacVwFields.Status == "ACTIVE"); bucket.PredicateExpression.Add(FacVwFields.FacId == facId);

        ExcludeIncludeFieldsList exincludeFields = new ExcludeIncludeFieldsList();
        exincludeFields.ExcludeContainedFields = false;


        for (int fieldsCount = 0; fieldsCount < includeFields.Length; fieldsCount++)
        {
            exincludeFields.Add(includeFields[fieldsCount]);
        }



        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            adapter.FetchEntityCollection(results, exincludeFields, bucket);

        }
        return results;
    }

aspx code

protected void bindFac(string facId) { ChannelFactory<IFacService> facFactory = new ChannelFactory<IFacService>("facService"); IFacService facServer = facFactory.CreateChannel(); using (facServer as IDisposable) {

            IEntityField2[] includeFields = new IEntityField2[2]{FacVwFields.MessageId,FacVwFields.Message};



                           EntityCollection facCollection = (EntityCollection)facServer .getFac(facId, includeFields);
            RadGrid facGrid = (RadGrid)RadPanelBar1.FindItemByValue("PanelItem1").FindControl("RadGridFac");
            facGrid .DataSource = facCollection ;
            facGrid .DataBind();
        }
    }

I am fairly new to LLBLGen and WCF so please let me know what I am doing wrong. Let me know if you need any other information.

Thanks Sam

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 02-Mar-2010 12:30:21   

Reproduced. Looking into it.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 03-Mar-2010 11:10:30   

You have to specify EntityField2 as a known type too, that's what the error says, though I'm not sure if that will solve your problem. ExcludeIncludeFieldsList isn't serializable to xml.

Serializing fields to xml (as xml is used to pass the elements) is problematic in a standalone fashion because they're created with a factory, and deserialization simply re-instantiates them without the factory.

So I'd suggest the following: Use the entity's fieldindex enum to gather the values for the fields to include/exclude and pass these as a List<int> to the service. In the service, you create the ExcludeIncludeFieldsList instance and use the int values to pass to the entity's fieldfactory (cast the int back to the entity's fieldindex enum, e.g. CustomerFieldIndex), like:

// service code
ExcludeIncludeFieldsList includeFields = new ExcludeIncludeFieldsList(false);
// fieldIndexes is the List<int> with field indexes
foreach(int index in fieldIndexes)
{
    // say we want to include customer fields
    includeFields.Add(EntityFieldFactory.Create((CustomerFieldIndex)index));
}
// use includeFields here
Frans Bouma | Lead developer LLBLGen Pro
samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 03-Mar-2010 21:59:46   

I specified EntityField2 also as the service type. But I am still getting error

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 04-Mar-2010 10:23:33   

Frans was suggesting sending List<int> as the indices of the fields from the fieldindex enum. I think hat's the only way around.