Json System.ServiceModel.Web.WebOperationContext.CreateTextResponse错误

Json System.ServiceModel.Web.WebOperationContext.CreateTextResponse错误,json,wcf,jsonp,Json,Wcf,Jsonp,它在我使用的VS2010目标框架CreateTextResponse上的编译是3.5 错误: “System.ServiceModel.Web.WebOperationContext”不包含“CreateTextResponse”的定义,并且找不到接受“System.ServiceModel.Web.WebOperationContext”类型的第一个参数的扩展方法“CreateTextResponse”(是否缺少using指令或程序集引用?) 引用该方法的文档: 支持人数:4人 这基本上意味着

它在我使用的VS2010目标框架CreateTextResponse上的编译是3.5 错误:

“System.ServiceModel.Web.WebOperationContext”不包含“CreateTextResponse”的定义,并且找不到接受“System.ServiceModel.Web.WebOperationContext”类型的第一个参数的扩展方法“CreateTextResponse”(是否缺少using指令或程序集引用?)


引用该方法的文档:

支持人数:4人


这基本上意味着.NET4.0中引入了这种方法。如果您的目标是.NET3.5,则无需查找它。我想是时候升级了:-)

这里有一个替代方法:。你能告诉我或者我可以使用response.write方法吗?下载示例应用程序并使用包含的类生成JSONP响应。我已经下载并查看了它,但没有了解如何使用,有没有博客对此进行解释?ms help真让我困惑。回答如下:
[OperationContract] 
[WebInvoke(UriTemplate = "", Method = "GET",  
    BodyStyle=WebMessageBodyStyle.Bare, 
    ResponseFormat = WebMessageFormat.Json)] 
public Message Blah() 
{ 
    var j = new { Name = "blah1", Data = "blah2" }; 

    JavaScriptSerializer s = new JavaScriptSerializer(); 
    string jsonClient = s.Serialize(j); 

    return WebOperationContext.Current.CreateTextResponse("method(" + jsonClient + ");", 
        "application/json; charset=utf-8", Encoding.UTF8); 
}