crossrider を使用してブラウザ拡張機能を作成しています。この拡張機能のインストールが完了したら、wcf サービスを呼び出す必要があります。chrome、firefox、safari では問題なく動作していますが、IE ではエラー 400 という badrequest エラーが表示されます。以下は私の Crossrider コードです。
appAPI.request.post({
url: 'http://183.82.102.245:8020/Service1.svc/json/GetAffiliatedUrlsCollection',
onSuccess: function(response) {var site = appAPI.JSON.parse(response);
AddUrlsToDB(site);
},
onFailure: function(httpCode) {
alert('Failed to retrieve content. (HTTP Code:' + httpCode + ')');
},
additionalRequestHeaders: {
myHeader: 'value'
},
contentType: 'application/json'
});
以下は私のサービスコードです
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "GetAffiliatedUrlsCollection", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
List<UrlInfo> GetAffiliatedUrlsCollection();
以下は私のプロパティです
[DataContract]
public class UrlInfo
{
private string affiliatedurl;
public string websiteurl;
public bool autoapprove;
public UrlInfo(string websiteurl, string affiliatedurl, bool autoapprove)
{
this.websiteurl = websiteurl;
this.affiliatedurl = affiliatedurl;
this.autoapprove = autoapprove;
}
[DataMember]
public string WebsiteUrl
{
get { return websiteurl; }
set { websiteurl = value; }
}
[DataMember]
public string AffilateUrl
{
get { return affiliatedurl; }
set { affiliatedurl = value; }
}
[DataMember]
public bool AutoApprove
{
get { return autoapprove; }
set { autoapprove = value; }
}
}
次にGlobla.asax
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, x-requested-with");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}