System.ServiceModel.Web.WebOperationContext.CreateTextResponse错误

时间:2010-11-18 18:11:36

标签: json wcf jsonp

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

'System.ServiceModel.Web.WebOperationContext'不包含'CreateTextResponse'的定义,也没有扩展方法'CreateTextResponse'接受类型'System.ServiceModel.Web.WebOperationContext'的第一个参数'(你错过了使用指令或汇编引用吗?)

[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); 
} 

1 个答案:

答案 0 :(得分:0)

引用CreateTextResponse方法的文档:

  

支持:4

这基本上意味着此方法已在.NET 4.0中引入。如果您的目标是.NET 3.5,则无需查找。猜猜是时候升级了: - )