Method not Allow

Nov 30 2018 12:28 AM
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 
  1. <?xml version="1.0"?>  
  2. <configuration>  
  3. <system.web>  
  4. <authorization>  
  5. <allow users="*"/>  
  6. </authorization>  
  7. <compilation debug="true" targetFramework="4.6.1"/>  
  8. <httpRuntime/>  
  9. </system.web>  
  10. <system.serviceModel>  
  11. <services>  
  12. <service name="EmpAppAJAX.Service.Service1">  
  13. <endpoint address="rest" behaviorConfiguration="restb" binding="webHttpBinding" contract="EmpAppAJAX.Service.IService1" ></endpoint>  
  14. <endpoint name="mexHttpBinding" address="mex" binding="mexHttpBinding" contract="EmpAppAJAX.Service.IService1" />  
  15. </service>  
  16. </services>  
  17. <bindings>  
  18. <webHttpBinding>  
  19. <binding>  
  20. <security mode="None"/>  
  21. </binding>  
  22. </webHttpBinding>  
  23. </bindings>  
  24. <behaviors>  
  25. <endpointBehaviors>  
  26. <behavior name="restb">  
  27. <webHttp/>  
  28. </behavior>  
  29. </endpointBehaviors>  
  30. <serviceBehaviors>  
  31. <behavior>  
  32. <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>  
  33. <serviceDebug includeExceptionDetailInFaults="false"/>  
  34. </behavior>  
  35. </serviceBehaviors>  
  36. </behaviors>  
  37. <protocolMapping>  
  38. <add binding="basicHttpsBinding" scheme="https" />  
  39. </protocolMapping>  
  40. </system.serviceModel>  
  41. </configuration>  
Service:
  1. [OperationContract]  
  2. [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "AddRoles")]  
  3. void AddRole(Roles objRole);  
  4. [OperationContract]  
  5. [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "GetRoles")]  
  6. List<Roles> GetRoles();  
  7. [OperationContract]  
  8. [WebInvoke(Method = "Post", RequestFormat = WebMessageFormat.Json, UriTemplate = "DeleteRole")]  
  9. void DeleteRole(Roles objRole);  
Ajax Code:
  1. //function for deleting role's record  
  2. function Delele(ID) {  
  3. debugger;  
  4. var ans = confirm("Are you sure you want to delete this Record?");  
  5. if (ans) {  
  6. var objRole = {  
  7. "Id": ID,  
  8. "RoleName""",  
  9. "RoleDescription"""  
  10. };  
  11. debugger;  
  12. $.ajax({  
  13. url: "http://localhost:63665/Service/Service1.svc/rest/DeleteRole",  
  14. type: "POST",  
  15. data: JSON.stringify(objRole),  
  16. dataType: "json",  
  17. contentType: "application/json;charset=UTF-8",  
  18. success: function (result) {  
  19. alert("deleted");  
  20. },  
  21. error: function (errormessage) {  
  22. debugger;  
  23. alert(errormessage);  
  24. }  
  25. });  
  26. }  
  27. }  
this is the code for insert the data that time their is no error....
  1. $("#btnSubmit").click(function () {  
  2. var objRole = {  
  3. "RoleName": $("#txtRole").val(),  
  4. "RoleDescription": $("#txtRoleDescription").val()  
  5. };  
  6. debugger;  
  7. $.ajax({  
  8. url: "http://localhost:63665/Service/Service1.svc/rest/AddRoles",  
  9. type: "POST",  
  10. data: JSON.stringify(objRole),  
  11. dataType: "json",  
  12. contentType: "application/json;charset=UTF-8",  
  13. success: function () {  
  14. debugger;  
  15. //console.info(result);  
  16. alert('Inserted');  
  17. // getData();  
  18. },  
  19. failure: function (msg) {  
  20. console.info(msg);  
  21. }  
  22. });  
  23. });  
Please someone help me...

Answers (2)