Calling WCF Service using JQuery RRS feed

  • Question

  • User1216489373 posted

    Hi Experts,

    I am not able to get Data from my WCF service while running the JQuery script, while when I run the same script for my webservice after chaning the URL I am getting the data. My WCF service is executing perfectly. The binding used is default basicHttpBinding. My jquery code for WCF is  as follows:-

                    function getEmployeeWCF() {
                            type: "POST",
                            url: "http://localhost:1314/Service1.svc/GetData",
                            //data: "{}",
                            data: "{'Id':'" + $('#txt1').val() + "'}",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (response) {
                                var employee = response.d;
                                        $.each(employee, function (index, emp) {
                                            $('#output').append('<p></strong><br /> Id: ' +
                                                    emp.Id + '<br />Name: ' +
                                                    emp.Name + '<br />Salary: £' +
                                                    emp.Salary + '<br />Department: ' +
                                                    emp.Department + '</p>');
                            failure: function (msg) {

    Please Help,


    Monday, May 12, 2014 12:35 PM


  • User-417640953 posted

    Hi Rahul_agg11,

    Thank you post the issue to asp.net forum.

    type: "POST",

    url: "http://localhost:1314/Service1.svc/GetData",

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

    For this issue, I suggest note below points.

    # Make sure your svc service works as rest service, add Invoke attribute on the service method like below.

        [WebInvoke(Method = "POST", 
         BodyStyle = WebMessageBodyStyle.Wrapped, 
         ResponseFormat = WebMessageFormat.Json)]
        string[] GetUser(string Id);

    # Enable your service can be consumed by config the service as web programing like below.

        <behavior name="EndpBehavior">

    # Config your service can be consumed cros domain like below.

    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type" />

    For complete example, please follow below article.


    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 13, 2014 10:57 AM