IQueryable problems using WCF

I have a pretty simple WCF service method that returns IQueryable, for testing only. Maybe something is wrong with me when I try to understand what IQueryable is for. I clearly plan to use this with the IQueryable NHibernate provider later. But first, I ran into some serialization issues (at least I think it might be a problem) when using the WCF method returning IQueryable. This does not even work for a simple string.

Here is my code:

public IQueryable<string> GetEquipmentConfigurations() { var returnValue = new List<string>(); returnValue.Add("test"); return returnValue.AsQueryable(); } 

It might not make much sense, it's just to check if I really get these IQueryables wiring using WCF. Whenever I call this method with a client such as SoapUI, I get a socket exception and a reset connection, just as if I were trying to return something that is not marked as DataContract. But the only thing I am doing here is trying to return some lousy list of strings. What is wrong with this?

I am using basicHTTPBinding, here are my settings:

 <system.serviceModel> <services> <service name="EquipmentConfigurationService" behaviorConfiguration="DefaultBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/Krones.KBase/Services/EquipmentConfigurationService"/> </baseAddresses> </host> <endpoint address="" binding="basicHttpBinding" contract="Krones.MES.KBase.Public.Service.EquipmentDefinition.IEquipmentConfigurationService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="DefaultBehavior"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="True"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> 

The OperationContract attribute is set for the interface:

 [OperationContract] IQueryable<string> GetEquipmentConfigurations(); 

Everything works well, just returning a simple string. Anyway, I want to profit from IQueryable functions using LINQ later.

Does anyone know what is going wrong here?

Thanks and greetings

Stephen

+7
c # wcf iqueryable
source share
2 answers

(Deprecated) AFAIK it is impossible to serialize IQueryable <> or Expression trees (think about this - this would mean that the expression / lambda tree should be serialized and the function rebuilt)

However, when there is a will, it seems that there is a way - you can look at projects like this http://code.msdn.microsoft.com/exprserialization

Change Please note that time has changed. See WCF RIA services according to Marc Gravell's post.

Good luck

NTN

+5
source share

The main WCF is for sending data , not requests. Stick to returning List<Foo> etc .; it will save you a lot of scratches on your head.

However, you may be able to do what you need with the help of WCF data services , which allows you to discover IQueryable<> sources.

The way this works is that the toolkit creates a client that provides similar IQueryable<> search hooks; when requesting data, it is an expression on the explorer, requests data and returns it to the client. But still the results (not the query) pass through the wire.

+10
source share

All Articles