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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:02:32+00:00 2026-06-06T01:02:32+00:00

I am trying to make an ajax GET request to a WCF web service

  • 0

I am trying to make an ajax GET request to a WCF web service method through javascript. The request returns with a 400 “Bad Request” error everytime. But if I invoke the same web service method through the WCF Test Client, it returns the correct results.

Also, the ajax call through javascript returns the bad request error on both GET and POST requests.

I have added the [WebGet] attribute to my web service method but the error still persists.

Here is my javascript method and ajax call:

function Getdata()
{
var methodUrl = serverUrl + "/GetData";
      $.ajax({
    async: false,
                 type: "GET",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    url: methodUrl,
    beforeSend: function (XMLHttpRequest) {
    //ensures the results will be returned as JSON.
    XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    success: function (data) {

    },
    error: function (XmlHttpRequest, textStatus, errorThrown) {
        alert("ERROR: GetData() Check your browsers javascript console for more details." + " \n XmlHttpRequest: " + XmlHttpRequest + " \n textStatus: " + textStatus + " \n errorThrown: " + errorThrown);
    }
});
}

Here, serverUrl is of the format: “http://hostname:portnumber/webServiceProxy.svc”

Any idea why the request would return a “Bad Request” error when invoked through javascript and work perfectly when invoked through the WCF Test Client? Any inputs will be appreciated! Thank you!

Also, I have compared the requests sent out from the WCF Test Client and from my AJAX request using Fiddler and here is what I see:

WCF Test Client Request:

POST http://hostname:portnumber/WebServiceProxy.svc HTTP/1.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tempuri.org/IWebServiceProxy/GetData"
Host: hostname:portnumber
Content-Length: 144
Expect: 100-continue
Accept-Encoding: gzip, deflate

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetData xmlns="http://tempuri.org/"/></s:Body></s:Envelope>

My AJAX Request:

GET http://hostname:portnumber/WebServiceProxy.svc/GetData HTTP/1.1
Content-Type: application/json; charset=utf-8
Accept-Language: en-us
Referer: http://hostname/OrgName/WebResources/resourceName?pagemode=iframe
Accept: application/json
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; InfoPath.3; .NET4.0E; BOIE9;ENUS)

Host: hostname:portnumber
Connection: Keep-Alive

So the biggest difference that I see is that the WCF Test Client makes a POST request and sends the web service method name in a SOAP envelope while my ajax request is a GET and adds the web service method name to the url. Looking at these requests, any ideas on how I might have to change my ajax call to get it to work correctly? Thanks!

Editing to add my web.config file contents:

<?xml version="1.0"?>

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <customErrors mode="Off" />
</system.web>

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IDDSWCFService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://machinename:8080/DDSWCFService" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_IDDSWCFService" contract="WCFService.IDDSWCFService"
            name="WSHttpBinding_IDDSWCFService">
            <identity>

            </identity>
        </endpoint>
    </client>
    <behaviors>
        <serviceBehaviors>

            <behavior>
                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                <serviceMetadata httpGetEnabled="true"/>
                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>

        </serviceBehaviors>

        <endpointBehaviors>
            <behavior name="webHttpBehavior">
                <enableWebScript/>
                <webHttp helpEnabled="true"/>
            </behavior>
        </endpointBehaviors>

    </behaviors>
</system.serviceModel>

  • 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-06T01:02:36+00:00Added an answer on June 6, 2026 at 1:02 am

    Thanks for all the responses. Surprisingly enough, I managed to fix the error, but the solution was totally not what I was expecting. I had to add an additional attribute to the markup of the Service1.svc file:

    Factory=”System.ServiceModel.Activation.WebScriptServiceHostFactory

    I am not sure why this wasn’t automatically added to the file when the project was built, but thats what did it. I am now able to invoke the Test method through the browser as well as through my AJAX request with no problem.

    Thanks again for everybody’s help.

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

Sidebar

Related Questions

I'm trying to make an AJAX GET request, but I simply cannot get it
I am trying to make my first AJAX Control and I get error. I
I'm trying to make some ajax-functionality in my web application, but I cannot get
I'm trying to make an ajax-request to vimeo to get data from an vimeo
I am trying to make a PUT request to a RESTful web service, however,
I am trying to make an ajax call using $.get() where I want to
I'm trying to make an ajax request recursively upon each success response that is
So, I'm trying to make cross-site AJAX request from my own script to the
I've been trying to make an AJAX request to an external server. I've learned
I'm trying to make a proxy-like page that forwards an AJAX request to 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.