最近、私はEF4でWCFの快適なサービスをセットアップしました。 XMLフォーマットのレスポンスを返すときは、すべてうまくいっています。しかし、それはJSONになると、私は504エラーがあります。サービストレースビューアを使用して、深く掘ってunable to return json data, WCF Resful Service .NET 4.0Entity Framework Complexを使用してWCF JSONを快適に返す
: 私はこのエラーを検出しました:
'The type 'xxx.DataEntity.AppView' cannot be serialized to JSON because its IsReference setting is 'True'. The JSON format does not support references because there is no standardized format for representing references. To enable serialization, disable the IsReference setting on the type or an appropriate parent class of the type.'
「APPVIEWは、」ストア手順からEF4によって生成された複雑なオブジェクトクラスです。 私はIsReferenceを無効にする方法をかなり時間を費やして、これまでのところほとんど結果を得ていません。
誰ですか?どんなソリューションでも?事前に
おかげ
コード:
[OperationContract]
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "App/{id}/{format}")]
AppView FuncDetail(string id, string format);
public AppView FuncDetail(string id, string format)
{
SetResponseFormat(format);
return AppSvcs.GetById(id);
}
private void SetResponseFormat(string format)
{
if (format.ToLower() == "json")
{
ResponseContext.Format = WebMessageFormat.Json;
}
else
{
ResponseContext.Format = WebMessageFormat.Xml;
}
}