I don’t remember how I got this error and when. But, since many people had this problem, I decided to publish what I did.
WCF - IService
[OperationContract] [WebGet(BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "SetJSON?data={data}")] string SetJSON(string data);
WCF - Service
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Service : IService { public string SetJSON(string data) { return data; } }
WCF - web.config
<system.serviceModel> <bindings> <webHttpBinding> <binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" /> </webHttpBinding> </bindings> .... <services> <service name="RnDService.Service"> <endpoint address="" behaviorConfiguration="webHttpBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="RnDService.IService" /> </service> </services>
Jquery call
$.ajax({ type: "GET", url: "http://localhost:81/Test/Service.svc/SetJSON?data=" + "{ \"dl\":" + datalist + " }", contentType: "application/json; charset=utf-8", dataType: "jsonp", success: function (data) { alert(data.toString()); }, error: function (XMLHttpRequest, textStatus, errorThrown) { debugger; alert("Error Occured!"); } });
not 100% sure that solved my problem. Anyway, this will help someone. :)
source share