тип контента 'application / json; charset = utf-8 'не был ожидаемым типом' text / xml; кодировка = UTF-8'
При использовании firebug я получил эту ошибкуОшибка сети: 415 Невозможно обработать ... xt / xml; кодировка = UTF-8', - "http://localhost:59899/wsccc1/wscccService.svc/RunTts
в моем проекте asp.net MVC 4.
Код:
function ttsFunction() {
serviceUrl = "http://localhost:59899/wsccc1/wscccService.svc/RunTts";
var data = new Object();
data.text = $('#speak').val();
var jsonString = JSON.stringify(data);
$.ajax({
type: 'POST',
url: serviceUrl,
data: jsonString,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function() { alert('ok')},
error: function (xhr,status,error) {
console.log("Status: " + status);
console.log("Error: " + error);
console.log("xhr: " + xhr.readyState);
},
statusCode: {
404: function() {
console.log('page not found');
}
}
});
}
Сервисный код:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class wservice:Iwservice
{
public string RunTts(string value)
{
return value.ToUpper();
}
}
Интерфейс:
namespace service
{
[ServiceContract]
public interface Iwservice
{
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "RunTts")]
string RunTts(string text);
}
}
И веб-конфигурацию я использовал без файлов в WCF.