【发布时间】:2011-05-09 11:35:29
【问题描述】:
过去 2 年我一直在使用 REST(使用 WCF),但对 Entity Model 和 Linq 不熟悉,但我使用过 nHibernate。
我做了一个简单的服务如下:-
NorthwindModel [具有 Product、Order 和 Order_Detail 表的数据模型] ProductService 暴露为具有特定配置的 REST(不使用 WebServiceHostFactory)
服务合同:-
[ServiceContract]
public interface IProductService
{
[OperationContract]
[WebGet(
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)
]
IList<Product> GetProducts();
}
服务实现:-
public class ProductService : IProductService
{
#region IProductService Members
public IList<Product> GetProducts()
{
IList<Product> prodList = new List<Product>();
NorthwindEntities ne = new NorthwindEntities();
var query = from category in ne.Products select category;
prodList = query.ToList<Product>();
return prodList;
}
#endregion
}
服务标签:-
<services>
<service name="HellooData.ProductService" behaviorConfiguration="wcfJSONBehavior">
<endpoint address="" behaviorConfiguration="REST" binding="webHttpBinding"
contract="HellooData.IProductService" bindingConfiguration="RESTBINDING">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange" bindingConfiguration="RESTBINDING" />
</service>
</services>
绑定:-
<webHttpBinding>
<binding name="RESTBINDING" maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
尝试从浏览器调用服务后,我得到 “错误 324 (net::ERR_EMPTY_RESPONSE):服务器关闭连接但未发送任何数据” Chrome 中的错误和 Mozilla 中的空白页面.
已尝试调试,但数据被正确提取(77 条记录)并返回,没有任何异常。我不知何故对数据的配置或大小有疑问,但不确定。试过 篡改结果集(只有 2 个而不是 77 个)结果仍然相同。
有人能指出发生了什么问题吗?
【问题讨论】:
-
使用 Fiddler 检查您的数据是否已传输。你在使用延迟加载吗?
-
我做了以下事情:- 1)用字符串数据检查了响应,它有效! 2) 将响应更改为 null 并且有效! 3)做了一个空的回应,它不起作用! 4) 只保留一条记录而不是标准的 77,仍然不起作用。 5)制作了一个数据服务(使用DataFactory)并与EDM链接,令人惊讶的是它可以工作。我以某种方式怀疑产品类中属性的数据类型,但不确定。
-
你使用延迟加载吗?