Scriptish スクリプトからアクセスできるファイルがデータベースに存在するかどうかを確認するローカル WCF サービスを公開しようとしています。
Scriptish または Greasemonkey (GET または POST) からローカル URL を呼び出すことはできますか? ローカル マシンの IIS でホストされる WCF サービスを作成しましたが、サービスは正常に動作しています。ただし、Scriptish からサービスを呼び出そうとすると、Chrome/Firefox の [ネットワーク] タブに次のように表示されます。
Request URL: http://localhost/service/service.svc/MatchPartial
Request Method: OPTIONS
Status code: 405 Method Not Allowed
これが私のajax呼び出しです:
$.ajax({
url: 'http://localhost/service/service.svc/MatchPartial',
type: 'POST',
contentType: 'application/json; charset=UTF-8',
dataType: 'json',
processData: true,
data: '{ "partialFilename": "testing" }',
success: function (result) {
console.log(result);
}
});
私のメソッドは次のように装飾されています:
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public int MatchPartial(string partialFilename)
{
...
}
サービスクラスの上に次のものがあります。
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
私は自分のサービスに以下を追加しようとしましたが、うまくいきませんでした:
[WebInvoke(Method = "OPTIONS", UriTemplate = "*")]
public void GetOptions()
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
}
私はすべてを試したような気がします。どんな助けでも大歓迎です!