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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:12:44+00:00 2026-06-15T08:12:44+00:00

I am trying to set up a simple WCF REST service that we will

  • 0

I am trying to set up a simple WCF REST service that we will be able to call from jquery. When I visit the URL in the browser, I get a response back. When I attempt to send an HTTPRequest directly (using the Firefox plugin RESTClient), I get a response back. These responses look correct to me, containing headers and a string of JSON and apparently nothing else.

However, when I call this same service via a jquery.get() or jquery.post() call, nothing happens. Using the jquery.ajax() call reveals the error callback gets called, but to me the data given to the error callback doesn’t give me clues as to why this isn’t working.

<a id="thelink" href="javascript:void(0)">GO</a>
<script type="text/javascript">
    function doAjax() {
        $.ajax({type: "POST",
                dataType: "json", // see note below
                url: "http://localhost:54459/MySimpleService.svc/json/24",
                success: function(jqXHR, textStatus) {
                             alert("success");
                         },
                error: function(jqXHR, textStatus, errorThrown) {
                             alert("error");
                         }
               });
        }
    $('#thelink').click(doAjax);
</script> 

Note: for the dataType parameter I have tried all of “text”, “json”, “jsonp” and leaving the parameter off. Similarly, I have tried with both GET and POST (modifying the web service to respond to GET or POST respectively).

The method called at that endpoint doesn’t do anything spectacular that should be failing — it simply concatenates the string to a constant and returns (just testing at this point, it will clearly do more interesting things in the future)

Firefox shows me getting back 200 OK when I click the link.

The WCF service is running out of my Visual Studio 2010 debug environment. It hits breakpoints placed in the method that responds to this service method.

I have tried accessing the html posted above from a file on my local machine (port 80) as well as hosting it elsewhere, with the same results. Could this be a security issue?

The values passed to the error callback don’t seem terribly helpful:

  • jqXHR – readyState : 0, status : 0, statusText : error
  • textStatus – “error”
  • errorThrown – “”

So, why does my service seem to work, for GET or POST, when I call the url in a browser or RESTClient, but fail when I attempt to call it from jquery.ajax()?

EDIT: after more tests based on the comments I received, I tried hosting the page with the javascript on the same port as the web service, and this shows success. In my real-world scenarios, I won’t have the luxury of hosting the client side code and the web service on the same domain/port. I’m assuming this is a security model issue — where do I look to allow this sort of access (whitelisting domains/ports or otherwise)

  • 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-15T08:12:45+00:00Added an answer on June 15, 2026 at 8:12 am

    The issue seemed to be in my web.config; as we worked out in comments, the issue is one of cross-domain security. I was already using a webHttpBinding on my endpoint, but did not realize it needed to be configured:

    <system.serviceModel>
        <bindings>
            <webHttpBinding>
                <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
            </webHttpBinding>
        </bindings>
        ...
    </system.serviceModel>
    

    Setting crossDomainScriptAccessEnabled="true" seems to have done the trick. Note that I already have <serviceMetadata httpGetEnabled="true"/> as part of my service behavior.

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

Sidebar

Related Questions

I'm trying to call a WCF Service from XCODE that has an Object as
I'm trying to implement a very simple WCF service that returns JSON. I'm trying
I'm trying to set up a simple chat system with jQuery / Ajax ,
I'm trying to set up the simple syndication example from the Django docs, in
I am trying the simple senario of running a WCF service to return Active
I'm trying to create a client for a WCF service that I have hosted
I am trying to set up simple Cross-Origin Resource Sharing using jQuery (1.7.1) powered
Possible Duplicate: Calling a webservice that uses ISO-8859-1 encoding from WCF I am trying
8/5/11: Update near bottom of post I'm trying to call my WCF web service
I am trying to return some JSON from a WCF service. This service simply

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.