0

I have one Cross Domain WCF. I have already implemented the CORS on the service.

If the method don't have any parameter, then I can call it using JQuery Ajax.

But the problem is, when the method is having any parameter then some error is occurred after the JQuery Ajax call.

  $.support.cors = true;
  $.ajax({
    url: servicePath,
    crossDomain: true,
    type: 'POST',
    async: false,
    cache: false,
    data: '{"name": "xyz"}',
    contentType: "application/json; charset=utf-8",
    dataType: 'json',
    processData: true,
    success: function (response) {
      alert('s');
    },
    error: function (error) {
      alert(error.status + ' : ' + error.statusText);
    }
  })

Server Side Code

Ayan
  • 17
  • 4
  • is your service a webapi? can you pass the parameters in url,m lik yourservce.svc/parameter1/parameter2 ? – Ricardo Pontual Jun 21 '16 at 11:22
  • it is not webapi. it is wcf application. the method type is 'post'. – Ayan Jun 21 '16 at 11:55
  • since you can reach your endpoint without parameters, maybe this link can help you: http://stackoverflow.com/questions/3876784/calling-wcf-service-with-jquery-and-parameters – Ricardo Pontual Jun 21 '16 at 12:55

1 Answers1

0

Coulde you provide the complete error message? And what is your wcf web.config fiel. I guess you can add this attribute with your service file. Like below:[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)] public class Service1 { [WebGet(ResponseFormat = WebMessageFormat.Json)] public Customer GetCustomer() { return new Customer() { Name = "Pranay", Address = "1 Ahmedabad" }; } }

Grady
  • 1
  • 1