C# 返回Json异常

C# 返回Json异常,c#,wcf,facebook-graph-api,rest,C#,Wcf,Facebook Graph Api,Rest,如果您未提供有效的令牌,graph facebook API将返回此错误: { "error": { "type": "OAuthException", "message": "An access token is required to request this resource." } } 如果进行了有效调用,则返回json结果 在使用.net 4的WCF中,如何使用此方法返回相同的Json“exception”: [W

如果您未提供有效的令牌,graph facebook API将返回此错误:

{
"error": {
             "type": "OAuthException",
             "message": "An access token is required to request this resource."
         }
}
如果进行了有效调用,则返回json结果

在使用.net 4的WCF中,如何使用此方法返回相同的Json“exception”:

[WebGet(UriTemplate = "{id}")]
public SampleItem Get(string id)
{
   if (id.Length != 4)
      "how to return here the error since this method return a sample item class"????
   else
      return rep.GetSampleByID(id);
}

我想我找到了一条路。返回流并管理返回的内容类型

你是在问如何构建一个复制Facebook API响应的JSON字符串吗?不,实际上问题是如何返回它?你需要澄清你正在使用的SDK,如果有的话,以及JSON来自哪里(显然是Facebook,但返回它的是什么?)我自己生成JSON。如果出现错误,我希望返回sereliazed错误,如果一切正常,我将返回序列化类。但所有这些都是用同一种方法实现的。你只是想抛出一个WebProtocolException吗?我很困惑