Azure 405方法不允许出错...

时间:2012-03-03 19:52:29

标签: wcf azure

寻找一些有关此错误的帮助

我有一个Azure WCF服务,我从Javascript调用。但是当我从JavaScript调用我的WCF服务时,我收到以下错误:   - 405不允许的方法

在WCF服务上,服务接口如下所示:

[ServiceContract]
public interface ICSServiceLevel
{
    [OperationContract]
    [WebInvoke(Method = "POST",
      BodyStyle = WebMessageBodyStyle.WrappedRequest,
      RequestFormat = WebMessageFormat.Json,
      ResponseFormat = WebMessageFormat.Json,
      UriTemplate = "getservicelevel")]
    List<ServiceLevel> GetServiceLevel(long id);      
}

接口的实现:

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CSServiceLevel : ICSServiceLevel
{
    public List<ServiceLevel> GetServiceLevel(long id)
    {
        List<ServiceLevel> retValue;
        //...
        return (retValue);
    }
}

服务角色的Web.config是:

 <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"
});

有人看到问题可能是什么?此外,在服务的webrole的定义中,我确实使端点81

2 个答案:

答案 0 :(得分:0)

为什么使用POST动词而不是GET动词?您的方法名称意味着它是一个只读的幂等资源。

答案 1 :(得分:0)

您是否在.csdef文件中设置了端口81和444的绑定?

您可能还想联系Fiddler并确保您发送正确的信息。通常在JQuery中,您将数据作为对象传递,而不是预先序列化的JSON字符串,因此也可能导致问题。