[英]WebMethod: Turn off XML
I built an ASP.NET Web Service Application (.NET 3.5) with a simple WebMethod: 我使用简单的WebMethod构建了ASP.NET Web服务应用程序(.NET 3.5):
[WebMethod]
public string GetToken()
{
return "Hello";
}
The response looks like this: 响应如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://www.mywebsite.com/">Hello</string>
This works fine. 这很好。 However, one of my customers can't deal with the XML-Wrapper around the result string.
但是,我的一位客户无法处理结果字符串周围的XML包装器。 Is there a way to turn off the XML and just return the pure string "Hello" (without quotation marks of course ;-)).?
有没有一种方法可以关闭XML,而只返回纯字符串“ Hello”(当然不带引号;-))。
See here: http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx 看到这里: http : //weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx
Basically, to get the string back you'd have to return JSON result which, in turn, can Be accomplished either by issuing a POST from your PHP client or by adding 基本上,要取回字符串,您必须返回JSON结果,而该结果可以通过从PHP客户端发出POST或添加
[ScriptMethod(UseHttpGet=true)]
to your web method. 到您的网络方法。
Also, make sure you follow the steps outlined here: http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-web-services to create AJAX-enabled service in the first place. 此外,请确保您遵循此处概述的步骤: http : //www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-web-services在以下位置创建启用AJAX的服务第一名。 For example, you need to add
例如,您需要添加
[System.Web.Script.Services.ScriptService]
attribute to your class to allow it to behave like an AJAX service... 属性赋予您的类以使其表现得像AJAX服务...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.