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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:40:33+00:00 2026-05-11T08:40:33+00:00

Please look at the code below and help me to figure out what am

  • 0

Please look at the code below and help me to figure out what am I doing wrong in my web service code. I want to set up an asp.net web service that can be consumed using an JSONP. I am using Jquery at client side to access the site. Even after setting up proper attributes my web service still emits xml due to which the aynch call fails.

Web Service

[WebService(Namespace = 'http://tempuri.org/')] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  [System.Web.Script.Services.ScriptService] public class WebService : System.Web.Services.WebService {      public WebService () {          //Uncomment the following line if using designed components          //InitializeComponent();      }      [WebMethod]     [ScriptMethod(ResponseFormat= ResponseFormat.Json, XmlSerializeString=false, UseHttpGet=true)]     public string HelloWorld(int id, string __callback) {         return  __callback + '({message: 'Hello World'})';     }  } 

Web Service Response:

<?xml version='1.0' encoding='utf-8'?> <string xmlns='http://tempuri.org/'>test({message: 'Hello World'})</string> 

Web.Config:

<webServices>     <protocols>         <add name='HttpGet'/>         <add name='HttpPost'/>     </protocols> </webServices> <httpHandlers>     <remove verb='*' path='*.asmx'/>     <add verb='*' path='*.asmx' validate='false'          type='System.Web.Script.Services.ScriptHandlerFactory,              System.Web.Extensions, Version=3.5.0.0,              Culture=neutral, PublicKeyToken=31BF3856AD364E35'/>     <add verb='*' path='*_AppService.axd' validate='false'          type='System.Web.Script.Services.ScriptHandlerFactory,              System.Web.Extensions, Version=3.5.0.0,              Culture=neutral, PublicKeyToken=31BF3856AD364E35'/>     <add verb='GET,HEAD' path='ScriptResource.axd'          type='System.Web.Handlers.ScriptResourceHandler,              System.Web.Extensions, Version=3.5.0.0,              Culture=neutral, PublicKeyToken=31BF3856AD364E35'          validate='false'/> </httpHandlers> <httpModules>     <add name='ScriptModule'          type='System.Web.Handlers.ScriptModule, System.Web.Extensions,              Version=3.5.0.0, Culture=neutral,              PublicKeyToken=31BF3856AD364E35'/> </httpModules> 

Javascript

$.ajax({     type: 'GET',     contentType: 'application/json; charset=utf-8',     url: 'http://localhost:54404/jsonp/webservice.asmx/HelloWorld?id=2&__callback=?', //?jsonp=MatchSvcCallback     dataType: 'jsonp',     data: {},     //jsonp : 'MatchSvcCallback',     success: function(msg) {     alert('Inside success callback function'); // not being called      },     error: function(xhr, msg){         var response = JSON.parse(xhr.responseText);      }  }); 

The js code works with an handler, but fails for the webservice due to xml response.

  • 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. 2026-05-11T08:40:34+00:00Added an answer on May 11, 2026 at 8:40 am

    I think the problem here is because jQuery doesn’t set the Content-Type header in the HTTP request for HTTP GET’s when using $.ajax(). It only gets sent if the request type is ‘POST’. This seems to be the case for both dataType: 'jsonp' and dataType: 'json'.

    I tried your example and watched the request/response exchange in Fiddler and sure enough I don’t see Content-Type: application/xml; charset=UTF-8 being sent in the headers for HTTP GET requests. The header does get sent if using HTTP POST. I’m guessing the presence of this header is a cue for the ASP.NET web service plumbing to decide whether to return either a JSON or XML formatted response.

    It seems you’re not the only one with this problem, see the following article on the on Elegant Code website:

    Calling Remote ASP.NET Web Services from JQuery

    The solution appears to be one of the following:

    • Use a HttpModule to inject the Content-Type: application/xml; charset=UTF-8 header into the request stream as described in the article above.

    • Use a HttpHandler for the endpoint as you explained you were doing prior to using an ASP.NET web service.

    • Try Rick Strahl’s page based approach in the following article (which is in effect a HttpHandler anyway): JSONP for cross-site Callbacks.

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

Sidebar

Related Questions

Please have a look on the code below .. <div id=click_me>Save</div> <div id=blocks_sortable> <div
Please take a look at the html listed below and let me know why
I have just started to look at .NET 3.5 so please forgive me if
Hi please look at the HTML below. I am trying to use jQuery to
the code below is a jquery POST request javascript. i want to use the
Please suggest some good resources to start writing Java Web services.
Please help! I'm really at my wits' end. My program is a little personal
Ok I am still having some issues with this code below. I have received
I am doing a project where I want a person to enter the name
The code below continues many lines until it ends with a expected /veotherwise /vechoose.

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.