WebMethod: Turn off XML

I built an ASP.NET Web Service Application (.NET 3.5) with a simple WebMethod:

[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. Is there a way to turn off the XML and just return the pure string "Hello" (without quotation marks of course ;-)).?


See here: 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

[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. For example, you need to add

[System.Web.Script.Services.ScriptService]

attribute to your class to allow it to behave like an AJAX service...

链接地址: http://www.djcxy.com/p/56662.html

上一篇: Java WebService中没有更改Portname和Servicename

下一篇: WebMethod:关闭XML