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 8590097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:12:58+00:00 2026-06-11T23:12:58+00:00

We developed a .NET web service for mobile application several years ago. This service

  • 0

We developed a .NET web service for mobile application several years ago. This service is being called by iPhone/Android/Blackberry/WindowsPhone and all native apps developed by a third party. We added support for JSON, so some apps access this service using JSON calls, and some using SOAP.

The webservice returns JSON only when the request is sent with HTTP header Content-type: application/json.

We encountered a problem with one Android platform (specifically the Galaxy Nexus), where the Content-Type header is missing for GET requests. Our third party app developer tried many solutions but could not find a way to force send the Content-Type for GET requests.

However, we did notice that the Accept header is set correctly and sent, but I found no way to change the web service to use that header instead of Content-Type to return JSON in those cases.

Here is the example request, which results with XML response, and not JSON as needed.

GET /mobile/service.asmx/Logon?system=2&username='test'&password='1234' HTTP/1.1
Accept: application/json
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Connection: Keep-Alive

And excerpt from the webservice code:

    [WebMethod(
        BufferResponse = false,
        CacheDuration = 0
        )]
    [ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json) ]
    public LogonResponse Logon(int system, string username, string password)
    {
        return service.Logon(system, username, password);
    }

Is there a way to force JSON response in some way, or inspecting the Accept header to do so? (Other than migrating to WCF?)

If not, I was told by the app developer they use the Spring framework to make HTTP requests. If there’s a solution on how to make it work on the app side and force send the Content-Type header for GET requests, it’s also appreciated!

Thanks!

  • 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-11T23:12:59+00:00Added an answer on June 11, 2026 at 11:12 pm

    Thanks for the reply.

    Although setting the content-type did not solve the issue, it did point me in the right direction.

    The following solved it for me:

    [WebMethod( 
            BufferResponse = false, 
            CacheDuration = 0 
            )] 
        [ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json) ] 
        public LogonResponse Logon(int system, string username, string password) 
        { 
            return SetOutput<LogonResponse>(service.Identify(username, password));
        } 
    

    and the actual conversion:

        public static T SetOutput<T>(object response)
        {
            var accept = HttpContext.Current.Request.Headers["Accept"];
            var ctype = HttpContext.Current.Request.ContentType;
    
            if (string.IsNullOrEmpty(ctype) && !string.IsNullOrEmpty(accept)) 
                if (accept.ToLower().EndsWith("application/json"))
                {
                    var serializer = new JavaScriptSerializer();
                    var json = serializer.Serialize(response); 
                    HttpContext.Current.Response.ContentType = "application/json"; 
                    HttpContext.Current.Response.Write(json); 
                    HttpContext.Current.Response.End();
                }
            return (T)response;
        }
    

    Cheers!

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

Sidebar

Related Questions

I'm new to this android apps, so i developed a sample .net web service
From a .NET application, how do I consume a Web Service developed using gSoap
I have developed the WCF web service in vb.net in visual studio 2010 express
I have a ASP.net 3.5 web application developed in VB.net I am using iTextsharp
I have a web application developed in ASP.NET 2.0, deployed in a data center.
i have developed a web application asp.net C#. on a button click i am
I have developed a MVC web application with ASP.NET MVC and im just wondering
I have developed a asp.net web service and deployed on IIS 7.5 and windows
I have to develop an application, which will request to a web service developed
I have developed in c# 2 applications. One ASP .NET web service and a

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.