WCF with Jquery RRS feed

  • Question

  • User901332479 posted

    Dear Experts,

    My architecture is mvc2 in my view page i am calling following jquery ajax to call wcf service,  but it  is not calling  either success or failure , help me to get atleast failure part

                type: "POST",
                // url: "http://localhost:58748/TestWeb_service1.asmx/Test",
                url: "http://localhost:63263/Service1.svc/GetRefDoctorlist",
                data: '{"centerid": "' + 4 + '","RefName": "' + "a" + '"}',
                contentType: "application/json; charset=utf-8",
                processdata: true,
                dataType: "json",
                success: function (data) {
                    if (data.d != null) {

                        var s = data.d[0];
                    else {


                failure: function (msg) {



    The service is working fine in testing link

    the folowing is my web.config

          <service name="WCFranchise.Service1">
            <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" contract="MEDALL.IDAL.IAppointment"/>

        <client />
              <serviceDebug includeExceptionDetailInFaults="false" />
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            <behavior name="webScriptEnablingBehavior">
              <webHttp />
          <wsHttpBinding >
            <binding name="NoSecurity"  >
              <security mode="None" />

        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <modules runAllManagedModulesForAllRequests="true" />
            <add value="Service1.svc" />

    Wednesday, February 26, 2014 12:39 AM


  • User-417640953 posted

    Hi 1991harihara,

    Thank you post the issue to asp.net forum.

    Based on your description and code, I see you want to call the cross domain wcf service using jquery ajax.

    First, a wcf service should fit below conditions if it can be called by ajax.

        #The Service has to be decorated with WebInvoke/WebGet to be accessed from javascript.

        #<enableWebScript/> has to be added to the configuration for enabling script calls to WCF.

        #webHttpBinding is to be used for the WCF to behave as a REST service.

    When you want to perform "POST" or "GET" request on cross domain wcf service or normal service using jquery/javascript or ajax,

    the browser actually sends an "OPTIONS" verb call to your wcf service that is not mention in your wcf method attribute.

    So we should change these options we need to do some changes in web.config of hosted wcf service.

       <modules runAllManagedModulesForAllRequests="true" />
           <add name="Access-Control-Allow-Origin" value="*" />
           <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
        <standardEndpoint name="" crossDomainScriptAccessEnabled="true" />

    For more information, you can follow below blog.


    Hope this helps, thanks.

    Best Regards!


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 27, 2014 3:11 AM