当前位置:编程学习 > C#/ASP.NET >>

WCF返回值是不是不支持IQueryable<T>?

服务代码如下:

        public NorthwindEntities ctx = new NorthwindEntities();

        public IQueryable<Orders> GetOrders()
        {
            var query = from o in ctx.Orders
                        select o;

            return query;
        }

        public string Test()
        {
            var query = from o in ctx.Orders
                        select o;

            return query.First().Customers.CustomerID;
        }

   
Test执行是可以的,GetOrders就报错: 

接收对 http://localhost:44217/Service1.svc 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。有关详细信息,请参见服务器日志。

Server stack trace: 
   在 System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   在 System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   在 System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   在 IService1.GetOrders()
   在 Service1Client.GetOrders()

Inner Exception:
基础连接已经关闭: 接收时发生错误。
   在 System.Net.HttpWebRequest.GetResponse()
   在 System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

Inner Exception:
无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接。。
   在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   在 System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   在 System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)

Inner Exception:
远程主机强迫关闭了一个现有的连接。
   在 System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   在 System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
wcf linq  IQueryable --------------------编程问答-------------------- 你可以使用DataServiceQuery<T> 作为返回值类型,它继承了IQuerable

public class DataServiceQuery<TElement> : DataServiceQuery, 
IQueryable<TElement>, IEnumerable<TElement>, IQueryable, IEnumerable
--------------------编程问答-------------------- http://msdn.microsoft.com/en-us/library/dd673933.aspx

http://msdn.microsoft.com/en-us/library/cc668792.aspx --------------------编程问答-------------------- 回1楼



http://bbs.csdn.net/topics/试了下,貌似不行。。。。  

能否给个例子? --------------------编程问答--------------------
引用 2 楼 q107770540 的回复:
http://msdn.microsoft.com/en-us/library/dd673933.aspx

http://msdn.microsoft.com/en-us/library/cc668792.aspx


用的不是WCF Data Services,这玩意不支持的太多了。。。。。 --------------------编程问答-------------------- 最新的 ASP.NET WebApi 支持返回 IQueryable<T> --------------------编程问答--------------------
引用 5 楼 fangxinggood 的回复:
最新的 ASP.NET WebApi 支持返回 IQueryable<T>


求指点,求传送门 --------------------编程问答-------------------- http://nuget.org/packages/Microsoft.AspNet.WebApi.OData
补充:.NET技术 ,  Web Services
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,