System.ServiceModel.Web.WebOperationContext.CreateTextResponse 错误

发布于 2024-10-03 08:55:56 字数 759 浏览 1 评论 0原文

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

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

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

its complining on CreateTextResponse i am using VS2010 target framework is 3.5
error:

'System.ServiceModel.Web.WebOperationContext' does not contain a definition for 'CreateTextResponse' and no extension method 'CreateTextResponse' accepting a first argument of type 'System.ServiceModel.Web.WebOperationContext' could be found (are you missing a using directive or an assembly reference?)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左耳近心 2024-10-10 08:55:56

引用 CreateTextResponse 方法的文档:

支持:4

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

Quote from the documentation of the CreateTextResponse method:

Supported in: 4

This basically means that this method has been introduced in .NET 4.0. No need to look for it if you are targeting .NET 3.5. Guess it's time to upgrade :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文