Hi,
I'm new to WCF.
I'm getting the below error when I try to call a WCF service from jQuery.
Error Code 415 - 'Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.
Here is the ajax call from jQuery:-
$.ajax({
type: "POST",
url: "Service.svc/ConvertTemperatureSimple",
data: 2,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert("success");
},
error: function (err) {
alert(err.status + " - " + err.statusText);
}
});
And here is what I have in my web.config file:-
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
And here is OperationContart I have in the Service.svc.cs file:-
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
decimal ConvertTemperatureSimple(decimal t, string unit);
I'm using WCF 4 & VS 2010. Please let me know if you need additional information.
I even tried putting the below in web.config but that didn't help.
<protocolMapping>
<add scheme="http" binding="wsHttpBinding" bindingConfiguration="" />
</protocolMapping>
This time it gave me this error:-
415 - Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.
I can't get this to work. I'm thinking there must be something incorrect in my web.config file. Any help is appreciated.
Thanks
Jai
I'm new to WCF.
I'm getting the below error when I try to call a WCF service from jQuery.
Error Code 415 - 'Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.
Here is the ajax call from jQuery:-
$.ajax({
type: "POST",
url: "Service.svc/ConvertTemperatureSimple",
data: 2,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert("success");
},
error: function (err) {
alert(err.status + " - " + err.statusText);
}
});
And here is what I have in my web.config file:-
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
And here is OperationContart I have in the Service.svc.cs file:-
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
decimal ConvertTemperatureSimple(decimal t, string unit);
I'm using WCF 4 & VS 2010. Please let me know if you need additional information.
I even tried putting the below in web.config but that didn't help.
<protocolMapping>
<add scheme="http" binding="wsHttpBinding" bindingConfiguration="" />
</protocolMapping>
This time it gave me this error:-
415 - Cannot process the message because the content type 'application/json; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.
I can't get this to work. I'm thinking there must be something incorrect in my web.config file. Any help is appreciated.
Thanks
Jai