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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:54:56+00:00 2026-05-15T00:54:56+00:00

In ASP.net web service if the above isn’t specified , what is the response

  • 0

In ASP.net web service if the above isn’t specified , what is the response format by default?
Also, if my web service below:

[WebMethod()]
        public List<Sample> GenerateSamples(string[][] data)
        {
            ResultsFactory f = new ResultsFactory(data);

            List<Sample> samples = f.GenerateSamples();
            return samples;
        }

returns the list of objects, If I change the response format to JSON, I have to change the return type to string, then how do I access objects in my javascript?

Currently I call this web service in my JS such as:

 $.ajax({
    type: "POST",
    url: "http://localhost/TemplateWebService/Service.asmx/GenerateSamples",
        data: jsonText,

        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            var samples = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;

            if (samples.length > 0) {
                doSomethingHere(samples);
            } else {
                alert("No samples have been generated");
            }



        },

        error: function(xhr, status, error) {
            var msg = JSON.parse(xhr.responseText);
            alert(msg.Message);
        }

    });

What i noticed though, even though everything works perfectly fine, the eval statement never gets executed, which means that the web service always returns a string!

So my question is, is [ScriptMethod(ResponseFormat = ResponseFormat.Json)] necessary on the web service definition side?

The way things are now, I can use samples array and access each object and its properties as I normally would in any OOP code, which is very convenient, and everything works no problem, but I just wanted to make sure that I am not missing anything in my set up.

I took the basics of combining Jquery’s ajax with asp.net from Encosia side, and the response type wasn’t mentioned there – I read it on another site and am I not sure how vital it is.

http://www.codeproject.com/KB/webservices/JsonWebServiceJQuery.aspx

Lists 4 different changes on the asp.net web service side. I only have the first 2 – in my web.config. The service itself and the Sample class is implemented without any serialization, it does have properties though. I guess the web service is JSON by default? And as long as your objects have properties, they are serializable by default? That was my understanding until I read this article.

  • 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-05-15T00:54:57+00:00Added an answer on May 15, 2026 at 12:54 am

    The ResponseFormat attribute is not necessary. Including both client and server settings, only four things are required to do that:

    • Add the ScriptHandlerFactory HttpHandler in your web.config.
    • Decorate your web service(s) with the [ScriptService] attribute.
    • Request the service’s methods with the POST verb.
    • Request the service’s methods with a content-type of “application/json”.

    When you do those four things, the service methods’ responses will automatically be serialized as JSON.

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

Sidebar

Related Questions

i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
I'm trying to get ASP.Net to cache the response of a web service request
Consider a web service written in ASP.NET Web API to accept any number files
I have an ASP.net web service that I'm using for a web application which
I've written an ASP.NET web service that I would like a .NET 3.x application
I am migrating an ASP.NET Web Service toward WCF. The old Web Service endpoint
I have an ASP.NET web service running that accepts both HTTP POST and SOAP
I have an ASP.NET web service that I can access via a windows program
I've a asp.net web solution which references a web service from another web site
A web server running a ASP.NET web service. To use the web service you

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.