我最近成立了一个WCF服务Resful实体框架4.0 它与XML完美的,但是当我尝试在JSON格式返回它我无法返回JSON数据,WCF Resful服务.NET 4.0
HTTP/1.1 504 Fiddler - Receive Failure
Content-Type: text/html
Connection: close
Timestamp: 01:11:06.453
ReadResponse() failed: The server did not return a response for this request.
任何想法?
在此先感谢
编辑: 守则是很正常的,其实我想这样做的双向,但没有运气。
硬代码ResponseFormat方式:
[OperationContract]
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Deal/{id}")]
Deals XMLDealDetail(string id);
动态设置ResponseFormat方式:
[OperationContract]
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Deal/{id}/{format}")]
Deals XMLDealDetail(string id, string format);
public Deals XMLDealDetail(string id, string format)
{
OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;
if (format.ToLower() == "json")
{
context.Format = WebMessageFormat.Json;
context.ContentType = "application/json";
}
else
{
context.Format = WebMessageFormat.Xml;
}
//Deals is a Entity Class defined in edmx file
Deals deal = DealsServices.GetById(id);
return deal;
}
我在哪里丢失的?
也许显示你的代码会给我们更多的想法? – 2010-11-08 13:08:12
+1同样的问题,你有它工作的DJ? – andy 2010-11-08 23:35:29
添加代码,我猜这可能是一个设置问题,但有点失去了我应该看的方向 – 2010-11-09 02:36:37