【问题标题】:Azure 405 Method not allowed error...Azure 405 方法不允许错误...
【发布时间】:2012-03-21 21:39:05
【问题描述】:

寻求有关此错误的帮助

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

WCF 服务上的Service Interface 是这样的:

[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

【问题讨论】:

    标签: wcf azure


    【解决方案1】:

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

    【讨论】:

    • 更改它以获取接口定义和调用。但仍然得到同样的错误。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-11-30
      • 1970-01-01
      • 2021-12-20
      • 2017-11-13
      • 2016-12-02
      • 2012-10-25
      • 2015-11-25
      • 1970-01-01
      • 2014-10-04
      相关资源
      最近更新 更多