简体   繁体   中英

IIS converting Webservice output from JSON to XML

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!

您可能需要将ASP.NET 3.5 Web服务指向经典ASP.NET 2.0应用程序池,可以在Web服务的“高级设置”中执行此操作。

The problem was the formatting of the json request, whilst it was valid json, the asp.net webserive was still returning xml. Turned out to be nothing to do with the iis settings at all. Must have been a red herring on some other forums

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM