Can any one help me how to fix this error : Method not Allow in WCF post method through ajax
it is a simple asp.net application not MVC Application. I'm trying to perform CRUD Operation through WCF Service.
Here when im inserting the data then their is no problem but same method i copy for delete (written code for delete) then method not allow error showing .
Please help me any one....
here is me code...
Web.config
- <?xml version="1.0"?>
- <configuration>
- <system.web>
- <authorization>
- <allow users="*"/>
- </authorization>
- <compilation debug="true" targetFramework="4.6.1"/>
- <httpRuntime/>
- </system.web>
- <system.serviceModel>
- <services>
- <service name="EmpAppAJAX.Service.Service1">
- <endpoint address="rest" behaviorConfiguration="restb" binding="webHttpBinding" contract="EmpAppAJAX.Service.IService1" ></endpoint>
- <endpoint name="mexHttpBinding" address="mex" binding="mexHttpBinding" contract="EmpAppAJAX.Service.IService1" />
- </service>
- </services>
- <bindings>
- <webHttpBinding>
- <binding>
- <security mode="None"/>
- </binding>
- </webHttpBinding>
- </bindings>
- <behaviors>
- <endpointBehaviors>
- <behavior name="restb">
- <webHttp/>
- </behavior>
- </endpointBehaviors>
- <serviceBehaviors>
- <behavior>
- <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
- <serviceDebug includeExceptionDetailInFaults="false"/>
- </behavior>
- </serviceBehaviors>
- </behaviors>
- <protocolMapping>
- <add binding="basicHttpsBinding" scheme="https" />
- </protocolMapping>
- </system.serviceModel>
- </configuration>
Service:
- [OperationContract]
- [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "AddRoles")]
- void AddRole(Roles objRole);
- [OperationContract]
- [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetRoles")]
- List<Roles> GetRoles();
- [OperationContract]
- [WebInvoke(Method = "Post", RequestFormat = WebMessageFormat.Json, UriTemplate = "DeleteRole")]
- void DeleteRole(Roles objRole);
Ajax Code:
-
- function Delele(ID) {
- debugger;
- var ans = confirm("Are you sure you want to delete this Record?");
- if (ans) {
- var objRole = {
- "Id": ID,
- "RoleName": "",
- "RoleDescription": ""
- };
- debugger;
- $.ajax({
- url: "http://localhost:63665/Service/Service1.svc/rest/DeleteRole",
- type: "POST",
- data: JSON.stringify(objRole),
- dataType: "json",
- contentType: "application/json;charset=UTF-8",
- success: function (result) {
- alert("deleted");
- },
- error: function (errormessage) {
- debugger;
- alert(errormessage);
- }
- });
- }
- }
this is the code for insert the data that time their is no error....
- $("#btnSubmit").click(function () {
- var objRole = {
- "RoleName": $("#txtRole").val(),
- "RoleDescription": $("#txtRoleDescription").val()
- };
- debugger;
- $.ajax({
- url: "http://localhost:63665/Service/Service1.svc/rest/AddRoles",
- type: "POST",
- data: JSON.stringify(objRole),
- dataType: "json",
- contentType: "application/json;charset=UTF-8",
- success: function () {
- debugger;
-
- alert('Inserted');
-
- },
- failure: function (msg) {
- console.info(msg);
- }
- });
- });
Please someone help me...