title: WebInvoke POST "Method not allowed" in Wcf
body: <p>my Rest wcf service as below...</p>
  
  <pre><code>[ServiceContract]
  public interface IWinPhoneService
  {
  
  [OperationContract]
  [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "getkpimeasuredata", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped)]
  List&lt;MeasureData&gt; GetKpiMeasureData(DomainData data);
  
  
  [OperationContract]
  [WebGet(UriTemplate = "getdata/{value}", ResponseFormat = WebMessageFormat.Json)]
  string GetData(string value);
  
  
  // TODO: Add your service operations here
  }
  
  [DataContract]
  public class DomainData
  {
      [DataMember]
      public int? KPIId
      {
          get;
          set ;
      }
  
  [DataMember]
  public int? ScorecardId
  {
      get;
      set;
  }
  
  [DataMember]
  public short? CumulativeMonth
  {
      get;
      set;
  }
  
  [DataMember]
  public int? EngineeringOrgId
  {
      get;
      set;
  }
  
  [DataMember]
  public int? BusinessOrgId
  {
      get;
      set;
  }
  [DataMember]
  public int? DataValuetypeId
  {
      get;
      set;
  }
  
  }
  </code></pre>
  
  <p>and when I consume this service using Restsharp as below</p>
  
  <pre><code>string URL = "http://&lt;servername&gt;:8085/WinPhoneService.svc";
  
              RestClient client = new RestClient(URL);
  
              RestRequest request = new RestRequest("getkpimeasuredata",Method.POST);
              DomainData data = new DomainData();
              data.KPIId = 1006;
              data.ScorecardId = 3;
              data.EngineeringOrgId = 11;
              data.DataValuetypeId = 1;
              data.CumulativeMonth = 463;
              data.BusinessOrgId = 1;
  
              string json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
  
              json = "{\"data\" : " + json + "}";
  
              request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
              request.RequestFormat = DataFormat.Json;
   client.ExecuteAsync(request, response =&gt;
              {
                  if (response.StatusCode == HttpStatusCode.OK)
                  {
  
  
  
                  }
                  else
                  {
                      //NOK
                  }
              });
  </code></pre>
  
  <p>Even tried a webget method also as below..</p>
  
  <pre><code> RestClient client1 = new RestClient(URL);
              RestRequest request1 = new RestRequest(string.Format("getdata/{0}", 1), Method.GET);
              request1.RequestFormat = DataFormat.Json;
  
              var x = client1.ExecuteAsync(request1, response =&gt;
                  {
                      if (response.StatusCode == HttpStatusCode.OK)
                      {
  
                      }
                  });
  </code></pre>
  
  <p>Im able to the response.StatusCode as NotFound and even when I checked fiddler <strong>the service is not hitting at all</strong> and when I verified the service url 
   in composer im getting the error as
  "<strong>HTTP/1.1 405 Method Not Allowed</strong>"</p>
  
  <p>and even when I tried with Webclient as below</p>
  
  <pre><code>string URL = "http://&lt;servername&gt;:8085/WinPhoneService.svc";
              WebClient wclient = new WebClient();
              wclient.UseDefaultCredentials = true;
              wclient.Headers["Content-Type"] = "application/json";
  
  
              DomainData kpidata = new DomainData();
              data.KPIId = 1006;
              data.ScorecardId = 3;
              data.EngineeringOrgId = 11;
              data.DataValuetypeId = 1;
              data.CumulativeMonth = 463;
              data.BusinessOrgId = 1;
  
              string json = SerializeJson(kpidata);
              String str = wclient.UploadString(new Uri(URL ),"getkpimeasuredata",json);
  </code></pre>
  
  <p>Even here im getting <strong>"HTTP/1.1 405 Method Not Allowed"</strong> but atleast in this case its <strong>hitting the service as shown in fiddler</strong></p>
  
  <p>PFB the webconfig for the same...</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation&gt;
        &lt;assemblies&gt;
          &lt;add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
        &lt;/assemblies&gt;
      &lt;/compilation&gt;
      &lt;!--&lt;httpRuntime targetFramework="4.0" /&gt;--&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;webHttpBinding&gt;
          &lt;binding name="webCorpBinding"&gt;
            &lt;!--&lt;security mode="TransportCredentialOnly"&gt;
              &lt;transport clientCredentialType="Windows"&gt;&lt;/transport&gt;
            &lt;/security&gt;--&gt;
          &lt;/binding&gt;
        &lt;/webHttpBinding&gt;
  
      &lt;/bindings&gt;
      &lt;behaviors&gt;
  
        &lt;endpointBehaviors&gt;
          &lt;behavior name="RESTCorpBehavior"&gt;
            &lt;webHttp/&gt;
          &lt;/behavior&gt;
  
        &lt;/endpointBehaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true"  /&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
        &lt;service name="WinPhoneService.WinPhoneService"&gt;
          &lt;endpoint name="WinPhoneServiceeCorp" address="" binding="webHttpBinding" bindingConfiguration="webCorpBinding" behaviorConfiguration="RESTCorpBehavior"
           contract="WinPhoneService.IWinPhoneService" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;!--&lt;protocolMapping&gt;
        &lt;add binding="basicHttpsBinding" scheme="https" /&gt;
      &lt;/protocolMapping&gt;--&gt;
      &lt;!--&lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /&gt;--&gt;
    &lt;/system.serviceModel&gt;
    &lt;!--&lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
      --&gt;&lt;!--
          To browse web app root directory during debugging, set the value below to true.
          Set to false before deployment to avoid disclosing web app folder information.
        --&gt;&lt;!--
      &lt;directoryBrowse enabled="true" /&gt;
    &lt;/system.webServer&gt;--&gt;
  
  
    &lt;connectionStrings&gt;
      &lt;add name="ScaasEntities" connectionString="metadata=res://*/Scaas.csdl|res://*/Scaas.ssdl|res://*/Scaas.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;data source=&lt;servername&gt;;initial catalog=&lt;catalog&gt;;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&amp;quot;" providerName="System.Data.EntityClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
    &lt;/entityFramework&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Please help me regarding the same..</p>
  
  <p>the function which I use in win8 mobile app is </p>
  
  <pre><code>public async void  LoadKpiData()
          {
                         string URL = "http://rr1biscdevsql01:8085/WinPhoneService.svc/getkpimeasuredata;
              WebClient wclient = new WebClient();
              wclient.UseDefaultCredentials = true;
              wclient.Headers["Content-Type"] = "application/json";
  
              DomainData kpidata = new DomainData();
              kpidata.KPIId = 1006;
              kpidata.ScorecardId = 3;
              kpidata.EngineeringOrgId = 11;
              kpidata.DataValuetypeId = 1;
              kpidata.CumulativeMonth = 463;
              kpidata.BusinessOrgId = 1;
  
              string json = SerializeJson(kpidata);
              wclient.UploadStringAsync(new Uri(URL), json);
  
              wclient.UploadStringCompleted += (s, e) =&gt;
                  {
  
                  };
  
          }
  </code></pre>
  
  <p>and when I check in response for Restclient call got error as below</p>
  
  <pre><code> {"ErrorCode":"1001","ErrorMessage":"System.Data.EntityCommandExecutionException: The data reader is incompatible with the specified 'ScaasModel.GetKPIMeasureData_Result'. A member of the type, 'ParamName', does not have a corresponding column in the data reader with the same name.\u000d\u000a   at System.Data.Query.InternalTrees.ColumnMapFactory.GetColumnMapsForType(DbDataReader storeDataReader, EdmType edmType, Dictionary`2 renameList)\u000d\u000a   at System.Data.Query.InternalTrees.ColumnMapFactory.CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary`2 renameList)\u000d\u000a   at System.Data.Query.InternalTrees.ColumnMapFactory.CreateFunctionImportStructuralTypeColumnMap(DbDataReader storeDataReader, FunctionImportMapping mapping, EntitySet entitySet, StructuralType baseStructuralType)\u000d\u000a   at System.Data.EntityClient.EntityCommandDefinition.FunctionColumnMapGenerator.System.Data.EntityClient.EntityCommandDefinition.IColumnMapGenerator.CreateColumnMap(DbDataReader reader)\u000d\u000a   at System.Data.Objects.ObjectContext.CreateFunctionObjectResult[TElement](EntityCommand entityCommand, EntitySet entitySet, EdmType edmType, MergeOption mergeOption)\u000d\u000a   at System.Data.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, MergeOption mergeOption, ObjectParameter[] parameters)\u000d\u000a   at System.Data.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ObjectParameter[] parameters)\u000d\u000a   at ScaasWinPhone.Model.ScaasEntities.GetKPIMeasureData(Nullable`1 kPIID, Nullable`1 scorecardID, Nullable`1 cumulativeMonthCount, Nullable`1 engineeringOrgID, Nullable`1 businessOrgID, Nullable`1 dataValueTypeID, Nullable`1 debug, ObjectParameter errorText)\u000d\u000a   at ScaasWinphoneRepository.ScaasRepository.GetKpiMeasureData(Nullable`1 kpiId, Nullable`1 scorecardId, Nullable`1 cumulativeMonth, Nullable`1 engineeringOrgId, Nullable`1 businessOrgId, Nullable`1 dataValuetypeId)\u000d\u000a   at SCaaSWinPhoneService.SCaaSWinPhoneService.GetKpiMeasureData(KpiDomainData kpidata)"}
  </code></pre>
  
  <hr>
  
  <p>Rajesh 
  when I added 
  <code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]</code> in service and </p>
  
  <pre><code>&lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt;
  </code></pre>
  
  <p>in webconfig im getting error as The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'. </p>
  
  <p>Actually its working fine when I run service in localhost but its throwing the error when I host the service..Please help ....</p>