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

[复制链接]
查看11 | 回复7 | 2021-1-27 05:29:10 | 显示全部楼层 |阅读模式
服务代码如下:
publicNorthwindEntitiesctx=newNorthwindEntities();
publicIQueryableGetOrders()
{
varquery=fromoinctx.Orders
selecto;
returnquery;
}
publicstringTest()
{
varquery=fromoinctx.Orders
selecto;
returnquery.First().Customers.CustomerID;
}

Test执行是可以的,GetOrders就报错:
接收对http://localhost:44217/Service1.svc的HTTP响应时发生错误。这可能是由于服务终结点绑定未使用HTTP协议造成的。这还可能是由于服务器中止了HTTP请求上下文(可能由于服务关闭)所致。有关详细信息,请参见服务器日志。
Serverstacktrace:
在System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebExceptionwebException,HttpWebRequestrequest,HttpAbortReasonabortReason)
在System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpantimeout)
在System.ServiceModel.Channels.RequestChannel.Request(Messagemessage,TimeSpantimeout)
在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Messagemessage,TimeSpantimeout)
在System.ServiceModel.Channels.ServiceChannel.Call(Stringaction,Booleanoneway,ProxyOperationRuntimeoperation,Object[]ins,Object[]outs,TimeSpantimeout)
在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessagemethodCall,ProxyOperationRuntimeoperation)
在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessagemessage)
Exceptionrethrownat[0]:
在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessagereqMsg,IMessageretMsg)
在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32type)
在IService1.GetOrders()
在Service1Client.GetOrders()
InnerException:
基础连接已经关闭:接收时发生错误。
在System.Net.HttpWebRequest.GetResponse()
在System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpantimeout)
InnerException:
无法从传输连接中读取数据:远程主机强迫关闭了一个现有的连接。。
在System.Net.Sockets.NetworkStream.Read(Byte[]buffer,Int32offset,Int32size)
在System.Net.PooledStream.Read(Byte[]buffer,Int32offset,Int32size)
在System.Net.Connection.SyncRead(HttpWebRequestrequest,BooleanuserRetrievedStream,BooleanprobeRead)
InnerException:
远程主机强迫关闭了一个现有的连接。
在System.Net.Sockets.Socket.Receive(Byte[]buffer,Int32offset,Int32size,SocketFlagssocketFlags)
在System.Net.Sockets.NetworkStream.Read(Byte[]buffer,Int32offset,Int32size)

分 -->
回复

使用道具 举报

千问 | 2021-1-27 05:29:10 | 显示全部楼层
你可以使用DataServiceQuery作为返回值类型,它继承了IQuerable
publicclassDataServiceQuery:DataServiceQuery,
IQueryable,IEnumerable,IQueryable,IEnumerable
回复

使用道具 举报

千问 | 2021-1-27 05:29:10 | 显示全部楼层
http://msdn.microsoft.com/en-us/library/dd673933.aspx
http://msdn.microsoft.com/en-us/library/cc668792.aspx
回复

使用道具 举报

千问 | 2021-1-27 05:29:10 | 显示全部楼层
回1楼



http://bbs.csdn.net/topics/试了下,貌似不行。。。。
能否给个例子?
回复

使用道具 举报

千问 | 2021-1-27 05:29:10 | 显示全部楼层
引用2楼q107770540的回复:http://msdn.microsoft.com/en-us/library/dd673933.aspx
http://msdn.microsoft.com/en-us/library/cc668792.aspx

用的不是WCFDataServices,这玩意不支持的太多了。。。。。
回复

使用道具 举报

千问 | 2021-1-27 05:29:10 | 显示全部楼层
最新的ASP.NETWebApi支持返回IQueryable
回复

使用道具 举报

千问 | 2021-1-27 05:29:10 | 显示全部楼层
引用5楼fangxinggood的回复:最新的ASP.NETWebApi支持返回IQueryable
求指点,求传送门
回复

使用道具 举报

千问 | 2021-1-27 05:29:10 | 显示全部楼层
http://nuget.org/packages/Microsoft.AspNet.WebApi.OData
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行