none
405 Method not allowed

    Question

  • Hi all,

    Looking for some assistance with this error

    I have an Azure WCF service that I call from Javascript. However when I call my WCF Service from JavaScript, I get the following error:
     - 405 Method Not Allowed
     
     On the WCF service Service Interface looks like this:
       
      [ServiceContract]
        public interface ICSServiceLevel
        {
            [OperationContract]
            [WebInvoke(Method = "POST",
              BodyStyle = WebMessageBodyStyle.WrappedRequest,
              RequestFormat = WebMessageFormat.Json,
              ResponseFormat = WebMessageFormat.Json,
              UriTemplate = "getservicelevel")]
            List<ServiceLevel> GetServiceLevel(long id);      
        }


        
    The implementation of the interface:
       
    [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        public class CSServiceLevel : ICSServiceLevel
        {
            public List<ServiceLevel> GetServiceLevel(long id)
            {
                List<ServiceLevel> retValue;
                //...
                return (retValue);
            }
        }
       
    The Web.config for the service role is:
      
     <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <services>
          <service behaviorConfiguration="CloudWCFServiceBehavior" name="CSServiceLevel">
            <endpoint address="" binding="webHttpBinding" behaviorConfiguration="JsonEndpointBehavior"
            contract="Services.ICSServiceLevel" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="CloudWCFServiceBehavior">
              <useRequestHeadersForMetadataAddress>
                <defaultPorts>
                  <add scheme="http" port="81"/>
                  <add scheme="https" port="444"/>
                </defaultPorts>
              </useRequestHeadersForMetadataAddress>
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
          
          <endpointBehaviors>
            <behavior name="JsonEndpointBehavior">
              <webHttp/>
            </behavior>
          </endpointBehaviors>
        </behaviors>

        And finally the way I call it is :
       
    var data = '{ "id" : -1}';
        $.ajax({
            data: data, cache: false, success: populateCustomerGrid,
            type: "POST", dataType: "json", contentType: "application/json",
            url: "http://mydomain.cloudapp.net:81/CSServiceLevel.svc/getservicelevel"
        });


        
        
    Anybody see what the problem could be? Also, in the definition of the webrole for the service, I do make the endpoint 81

    thanks!
    Jas

    Saturday, March 03, 2012 6:30 PM

Answers

  • Hi,

    I would like to know whether you have made the solution work locally. I am not sure whether you are trying to access the service from the same web role, or from somewhere else. But please note, by default an in-browser JavaScript application cannot access cross site network resources. If you want to access the service from cross site, please make your service support cross site access control, you can refer to  http://www.w3.org/TR/2008/WD-access-control-20080214/ for detailed information.

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework

    Monday, March 05, 2012 9:57 AM
    Moderator

All replies

  • I seem to recall fixing this once by removing the WebDav handler.  Something like this, IIRC:

    <system.webServer>
     <modules>
                <remove name=”WebDAVModule” />
            </modules>
            <handlers>
                <remove name=”WebDAV” />
            </handlers>
    </system.webServer>


    Ryan Dunn -- Cumulux

    Saturday, March 03, 2012 8:16 PM
  • I think only the PUT and DELETE HTTP operations are blocked by the WebDav module on IIS. By default, a POST operation should be allowed, since this is commonly used in HTML as a form results in a POST operation.

    Nevertheless, you can try to see if this solves the issue, but I'd expect it more on the PUT and DELETE operation.


    Be nice to nerds ... Chances are you'll end up working for one!

    Saturday, March 03, 2012 8:39 PM
  • No, that did not solve it. Any other ideas? anyone?

    I also tried changing the
     [WebInvoke(Method = "POST",

    to a

     [WebInvoke(Method = "GET",

    and changed my call to

     $.ajax({
            data: data, cache: false, success: populateCustomerGrid,
            type: "GET", dataType: "json", contentType: "application/json",
            url: "http://mydomain.cloudapp.net:81/CSServiceLevel.svc/getservicelevel"
        });

    But still does not work...
    Sunday, March 04, 2012 1:31 AM
  • Have you tried to compose a GET HTTP request with Fiddler and checked if you get a result if you execute the HTTP request with Fiddler ?

    I tried to check whether I can access the service, but you have not specified the uri to your hosted service.
    And why exactly are you going through port 81 and not through the default port 80 ?


    Be nice to nerds ... Chances are you'll end up working for one!

    Sunday, March 04, 2012 9:07 AM
  • Hi,

    I would like to know whether you have made the solution work locally. I am not sure whether you are trying to access the service from the same web role, or from somewhere else. But please note, by default an in-browser JavaScript application cannot access cross site network resources. If you want to access the service from cross site, please make your service support cross site access control, you can refer to  http://www.w3.org/TR/2008/WD-access-control-20080214/ for detailed information.

    Best Regards,

    Ming Xu.


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework

    Monday, March 05, 2012 9:57 AM
    Moderator