0
votes

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

2

2 Answers

0
votes

Why are you using a POST verb instead of a GET verb? Your method name implies it is a read-only idempotent resource.

0
votes

Did you set up the bindings for port 81 and 444 in the .csdef file?

You might also want to hook up Fiddler and make sure you're sending the right thing. Normally in JQuery you would pass in the data as an object, rather than a pre-serialized JSON string, so that may be causing a problem as well.