クライアント側から AJAX を使用して JSON オブジェクトを WCF サービスに渡したいと思います。Internet Explorer ではすべて正常に動作しますが、firefox では動作しません。
Firefox で405:Method not allowed が表示される
これは、(クライアント スクリプトから) json データを WCF サービスに渡す場所です...
$(document).ready(function () {
var Author = '{ "Id": "A01", "Name": "Ravinder" }';
$.ajax({
type: "POST",
data: JSON.stringify(Author),
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "http://localhost:53905/Service1.svc/AuthorPostByJson",
success: function (data) {
alert("success");
},
error: function (xmlhttprequest, textstatus, errorthrown) {
alert(" failed ");
console.log("error: " + errorthrown);
}
});//end of $.ajax
});
私のWCFサービスは...
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "AuthorPostByJson",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
List<Book> GetBooksByAuthor_JSON(Author author);
私の web.config ファイル ....
<system.serviceModel>
<services>
<service behaviorConfiguration="Platform.WebRestful.Service1Behavior"
name="Platform.WebRestful.Service1">
<endpoint address="" binding="basicHttpBinding" contract="Platform.WebRestful.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="Platform.WebRestful.BookServiceHostRestfulBehavior"
name="Platform.WebRestful.BookServiceHostRestful">
<endpoint address="" binding="webHttpBinding" contract="Platform.WebRestful.IBookServiceHostRestful">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Platform.WebRestful.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="Platform.WebRestful.BookServiceHostRestfulBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>