tags:

views:

531

answers:

5

Func is a serializable class, but yet when I try to pass it as a parameter through a service. I'm told it "isn't a known type". I've tried the solutions here to no avail.

Many thanks out there...

+3  A: 

No, basically. You can't pass an Expression either, since it talks to MemberInfo nodes. Your best bet is a string representation of the predicate.

Marc Gravell
+4  A: 

There's work happening to enable it. Check out the Expression Tree Serialization project on the MSDN Code Gallery.

Matt Hamilton
That's really scary. Expressions are great for application code, but there are some serious security implications for service code.
Michael Meadows
Yeah, but I can imagine a sort of "Linq to the Cloud" project where you pass a "where" clause to a service, and it returns, say, the first 100 rows matching that clause.
Matt Hamilton
For that scenario, perhaps the type of wrapping that Astoria does is the way to go...
Marc Gravell
Sure. I guess it depends on what you're trying to do. As I understand Astoria, it's very "single-table" focused - it'd be hard to pass an expression that looked at Order.Customer.Address.State == "CA", for example.
Matt Hamilton
I am trying to do exactly the "where" scenario that you mentioned.
KevDog
+3  A: 

Wow, what a wild question - you're essentially asking, how do I serialise functions? Which seems quite strange from an OO perspective, but is a perfectly natural question from a functional perspective.

Interesting ...

Travis
A: 

Can you return any other delegate type in WCF? I don't think so. What would it even mean?

John Saunders
A: 

Hi,

Could you please explain a scenario where it would be useful to expose Func in the service boundary? Sniff, Sniff... it has a certain smell to it that I wouldn't characterize as proper service-orientation.

--larsw

larsw
I want to pass a func as a parameter in a service call for querying against the repository.
KevDog
I can see the use of it - but I still would not consider it a "kosher" thing to do - it would certainly be a bad option if you want your service to be interoperable.
larsw
Why? You make an assertion (not necessarily a bad thing) and don't give an explanation. And I think you are only allowed to say your own ideas smell, doesn't seem too nice without knowing the context of the problem. Regardless, I'm not the one who down-modded you on it.
KevDog
As for why sending a Func<blah, foo> will adversely affect interoperability, a Func is a .NET-specific Type. There is no generic mapping to XML, and then to PHP, Java, C, or anything else.
Cheeso