System.ServiceModel.Web.WebOperationContext.CreateTextResponse 错误
它对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用 CreateTextResponse 方法的文档:
这基本上意味着该方法已在.NET 4.0中引入。如果您的目标是 .NET 3.5,则无需查找它。猜猜是时候升级了:-)
Quote from the documentation of the CreateTextResponse method:
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 :-)