Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8059663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:44:41+00:00 2026-06-05T09:44:41+00:00

A little while ago, I managed to get WebServices to return JSON as well

  • 0

A little while ago, I managed to get WebServices to return JSON as well as XML from the code-behind of an ASPX.

Today, I needed to migrate an existing ASMX WebService to return JSON instead of XML (which was accomplished with little fuss). My problem became evident in testing the new method.

In the code-behind for the ASMX, I created a new method to return JSON instead of XML.
The method works, in that it returns the expected JSON however the new routine breaks every XML-returning method in the code-behind (they all throw “System.NotSupportedException: The type System.Collections.Hashtable is not supported because it implements IDictionary.” which is unexpected because the return types are all defined as XmlDocument).

If I simply comment out the JSON-returning method, the XML-returning methods function normally. Uncommenting out the JSON-returning method breaks the XML-returning methods again.

While I cannot find any supporting documentation anywhere, this behavior leads me to believe that in ASP.Net 2.0, JSON-returning methods cannot co-exist in the same module as XML-returning methods.

This led me to try separating the methods in sub-classes like so:

<WebService(Namespace:="http://tempura.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class MyWebServices
    Inherits System.Web.Services.WebService

    <ScriptService()> _
    Public Class xml
        Inherits System.Web.Services.WebService

        <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _
        Public Function MethodName As XmlDocument
            ...
        End Function
    End Class

    <ScriptService()> _
    Public Class json
        Inherits System.Web.Services.WebService

        <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
        Public Function MethodName As Hashtable
            ...
        End Function
    End Class
End Class

The idea being that I could then call the services in one of the following manners:

  • ~/MyWebServices.asmx/xml/MethodName
  • ~/MyWebServices.asmx/xml.MethodName
  • ~/MyWebServices.asmx/json/MethodName
  • ~/MyWebServices.asmx/json.MethodName

This unfortunately didn’t work, giving a 404-Not Found error.

I could simply throw all the JSON-returning methods into a different ASMX, but I am hoping for a better way.

My questions are thus:

  • Is there a way to accomplish ~/MyWebServices.asmx/xml/MethodName and ~/MyWebServices.asmx/json.MethodName? I like the idea of separating functions by return type in a virtual path.
  • Failing that, is there a way to get JSON-returning methods to co-exist in the same module as XML-returning methods?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:44:42+00:00Added an answer on June 5, 2026 at 9:44 am

    +1 to @smartcaveman for the attempt.

    The solution to this was a different (and I think better, overall) approach. Instead of explicitly returning either an XMLDocument (XML) or a HashTable (JSON), I instead wrote out a custom return object like so:

    <WebService(Namespace:="http://tempura.org/")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ScriptService()> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class MyWebServices
        Inherits System.Web.Services.WebService
    
        <WebMethod()> _
        <ScriptMethod()> _
        Public Function MethodName As CustomReturnObject
            ...
        End Function
    
    End Class
    

    I made sure that the custom return object implemented IXmlSerializable and now the Framework returns XML or JSON depending on the caller.

    If the caller specifies a contentType of application/xml, XML is returned.

    If the caller specifies a contentType of application/json, JSON is returned.

    I think this approach is better in that I don’t have to organize WebServices by return type, nor do I have to maintain two separate methods (one XML, one JSON) for each WebService I write.

    Thanks for at least looking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A little while ago I managed to get Visual Studio 2008 (C++) into a
As background, I gave an answer to this post a little while ago: Return
A little while ago I noticed some Soap errors emitting from my app and
A little while ago I created a class to deal with my LAN networking
I bought The D Programming Language a little while ago. Great book, very educational.
I have been trying this for a little while nut just cannot get to
A little while ago, I saw a question answered here regarding the fine-grained organization
Authenticating to our Ubuntu EC2 instance worked fine until a little while ago. All
This question is related to this initial question asked a little while ago. Now,
A while ago I developed a little LAN chat app. in Java which allows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.