我最近成立了一個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