Passing predicates to webservices

Posts   
 
    
astrouk
User
Posts: 53
Joined: 13-Jun-2006
# Posted on: 26-Aug-2006 03:30:32   

Hello,

I am trying to pass predicates to a webservice using two approaches below. Unfortunately both of them fail so farsimple_smile

LLBLGenPro 2.0.0.0 Selfservicing PredicateExpression: PredicateExpression(EmployeeFields.Lastname % "S%");

  1. Pass some parameters to a webmethod and create predicates there.

I am trying to implement "generic" predicate passing here. I mean that I'd like to pass a field I create predicate for as a parameter also. In this case this parameter is "Lastname" (It can be Firstname, Country, State etc.) However, I haven't figured out how to do it. EmployeeFields class doesn't contain any Items or Fields collection which could return EntityField by field's name. I have also tried to find some other way to do it. Unsuccessfully...

  1. Serialize a predicate using Soapformatter and pass it to webservice. However it didn't work either. Code:

IPredicate filter1 = new PredicateExpression(EmployeeFields.Lastname % "S%"); //I use filestream only for test purposes, of course FileStream fs = new FileStream("DataFile.soap", FileMode.Create); SoapFormatter formatter = new SoapFormatter(); formatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; formatter.Serialize(fs, filter1); fs.Close();

Exception message: Soap Serializer does not support serializing Generic Types : System.Collections.Generic.List`1[SD.LLBLGen.Pro.ORMSupportClasses.IPredicateExpressionElement]."

Thank you.

Alex

astrouk
User
Posts: 53
Joined: 13-Jun-2006
# Posted on: 26-Aug-2006 03:57:53   

astrouk wrote:

Exception message: Soap Serializer does not support serializing Generic Types : System.Collections.Generic.List`1[SD.LLBLGen.Pro.ORMSupportClasses.IPredicateExpressionElement]."

Binaryformatter works for Lists though... Anyway I would prefer approach number 1 if I knew how to do it.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39617
Joined: 17-Aug-2003
# Posted on: 26-Aug-2006 11:01:23   

The Soap formatter has been deprecated by MS for .NET 2.0. It's still available in the framework, but it can't deal with generics. If you must pass a predicate to a webservice, consider serializing it to a memorystream and Base64 the output into a string and send that over.

However I'd design the webservice in such a way that you can pass parameters to the webservice which are then used to build a predicate on the server.

Frans Bouma | Lead developer LLBLGen Pro
astrouk
User
Posts: 53
Joined: 13-Jun-2006
# Posted on: 26-Aug-2006 23:33:38   

Otis wrote:

However I'd design the webservice in such a way that you can pass parameters to the webservice which are then used to build a predicate on the server.

Well, I have to say that this was my preferable approach in order to implement passing predicates to a web service from the very beginning. However I don't know how to use an entity/types list property passed as a parameter while constructing a predicate at web service side. (See issue 1 in my initial post)

mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 27-Aug-2006 01:12:02   

Perhaps you might use

EntityFieldFactory.Create

.

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 27-Aug-2006 18:21:49   

The problem with trying to make a webservice abstract like this is that you inevitably begin to force the calling client into a platform-specific paradigm. If it's always a .NET to .NET scenario this might be OK, but web service standards will still have problems in many instances like this because you are always serializing and deserializing data through XML, and though we may think of web services as a way to use any object from any platform, this isn't necessarily true. You may need to lean towards an approach that does not necessarily allow for generic predicates, but instead exposes specific logic to the client. Code generation may help in a scenario like this as well.

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 28-Aug-2006 18:40:23   

I also think the webservice approach should be implemented according to some kind of simple message based mechanism instead of complex type which is more what remoting is meant for.

As for passing fields, you should indeed be fine with strings parameters.

The FieldInfoProviderSingleton would let you get the IEntityField given the entity name and field name. unfortunately it's marked as friend, so you'll have to rely on the factories instead.

As they deal with generated enums such as EntityType, you will have to do some converting there, but that works fine.

For instance, say you get entity name and field name as input parameters. cast the entity name to the corresponding EntityType Enum, then call yourEntityFields = CreateEntityFieldsObject( yourEntityType), and with the resulting IEntityFields you can use: yourEntityField = yourEntityFields(yourFieldName)

In the last resort, if you want to do more complicated things like playing with relations, relection also works fine, given the normalized syntax, but in that case you should make sure to cache your property descriptors because of the perfs overhead.

Hope that helps.