1

I am calling a web service, which returns xml instead of json. I've read a lot of topics here on SO, but nothing really helps.

Here is my call:

<script type="text/javascript">
    $(document).ready(function() {
        $("#myabtags").tagit({
            tagSource: function(request, response) {
                $.ajax({
                    type: "POST",
                    url: "Services/ForumServices.asmx/GetTags",
                    dataType: "application/json; charset=utf-8",
                    data: { prefixText: request.term, count: 10 },
                    success: function(data) {
                        response(data);
                    }
                });
            },
            removeConfirmation: true

        });
    });
</script>

Here is my webservice:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string[] GetTags(string prefixText, int count)
{
    var data = SystemContext.Instance.Tags;
    string prefixLower = prefixText.ToLower();
    return data.Where(c => c.Value.Contains(prefixLower) && c.IsVisible).OrderBy(c=>c.Value).Take(count).
        Select(c=>c.Value).ToArray();

}

This is my response:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
  <string>metafor</string>
  <string>tyngdekraft</string>
</ArrayOfString>

My web.config:

 <handlers>
       <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="AjaxToolkit" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>

I am running ASP.NET 4.0, using IIS 7.5.


So I basically want my call to return JSON.

Lars Holdgaard
  • 9,496
  • 26
  • 102
  • 182

0 Answers0