Я получаю ошибку CORS в Firefox для запроса WCF POST. Этот код отлично работает в Edge и Chrome. Ошибка видна только в Firefox. Кроме того, ошибка появляется в Firefox только тогда, когда я выполняю вызов с набором параметров данных и contentType, установленным в «Application / Json; charset = utf-8». Если изменить contentType на «text / plain», я получаю ошибку «400 bad request». Мой код выглядит следующим образом:
ОПЦИИ Heaer в WCF:
[WebInvoke(Method = "OPTIONS", UriTemplate = "*")]
public void GetOptions()
{
if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS")
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "https://localhost:5001");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS,HEAD,PUT,DELETE");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Max-Age", "1728000");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "x-requested-with, Content-Type, origin, authorization, accept, client-security-token");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Credentials", "true");
}
}
Почтовый метод, которым я звоню:
[WebInvoke(UriTemplate = "GetAttachmentsPost1", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle =WebMessageBodyStyle.Bare, Method = "POST")]
public void GetAttachmentsPost1( teststr teststr1)
{
string str = "abc";
}
[DataContract]
public class teststr
{
[DataMember]
public string teststr1 { get; set; }
}
The AJAX вызов службы:
$.ajax({
url: "http://127.0.0.1:5555/MyWCFService/GetAttachmentsPost1",
type: "POST",
data: JSON.stringify({ 'teststr1':'abc'} ),
xhrFields: {
withCredentials: true
},
contentType: "application/json; charset=utf-8",
crossDomain: true,
dataType: "JSON",
processData: true,
error: function (data) {
},
success: function (data) {
},
statusCode: {
404: function () {
// page not found
}
},
complete: function (data) {
},
});
Как я уже говорил выше, он отлично работает в Edge и Chrome, но не работает только в FF. В Edge и Chrome предварительный вызов выполняется в OPTIONS, но в FF вызов не идет.
Любая помощь приветствуется.
Спасибо.