This is a problem we've seen discussed in other places, with a couple of potential solutions, but we're unable to get any of them to work.
We have an ASP.net webservice set up to return results as JSON. We use JQuery $.post to get the results (but that's almost certainly not part of the issue.) When the results arrive on the client side, they have been wrapped in XML tags. So, instead of returning like this:
<?xml version="1.0" encoding="utf-8"?>
{data}
...they return like this...
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="[SomeURL.com]">{data}</string>
In the process of testing this we've discovered that the default in ASP.net 3.5 for webservice results was JSON, but that in ASP.net 4.0, this was changed to XML.
To try and test this we downloaded an ASP.net 3.5 test webservice application, and locally this output in JSON as expected. We then upgraded the application to 4.0, expecting this to begin outputting as XML. However, locally, it continued to output as JSON without the external tags.
Then, we moved this test application to our IIS 7.0 server, and it immediately began outputting as XML. This meant that the issue was to do with settings within IIS vs local settings.
We then found this post:
asmx web service returning xml instead of json in .net 4.0
...and have tried replacing the 4.0 Script Handler via web.config to the 3.5 version. However, this isn't working either. After our web.config amends, we then have the following in IIS' Handler Mappings area:
ScriptHandlerFactory - 3.5 version.
ScriptHandlerFactoryAppServices-Integrated-4.0 - 4.0 version.
...but also...
WebServiceHandlerFactory-Integrated - 2.0 version
WebServiceHandlerFactory-Integrated-4.0 - 4.0 version
WebServiceHandlerFactory-ISAPI-2.0
WebServiceHandlerFactory-ISAPI-2.0-64
WebServiceHandlerFactory-ISAPI-4.0_32bit
WebServiceHandlerFactory-ISAPI-4.0_64bit
So... that's where we are - messing with IIS settings to try and get the webservice to send as JSON. We're pretty certain that this is an IIS setting, or at least an ASP.net 4.0 vs 3.5 setting.
As background, the ASP.net webservice looks like this:
<System.Web.Script.Services.ScriptService(Namespace:="[SomeURL.com]")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class RequestM
Inherits System.Web.Services.WebService
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False, XMLSerializeString:=False)> _
Public Function dataRequestJSON(ByVal JsonRequestObject As String) As String
Try
Dim MyNewDataRequest As New DataRequest(JsonRequestObject)
Dim MyJsonResponse = MyNewDataRequest.JsonResponse
Return MyJsonResponse
Catch ex As Exception
Return ex.Message
End Try
End Function
Please help!
Thanks!