2012-03-03 233 views
0

尋找一些此錯誤的幫助Azure 405方法不允許錯誤...

我有一個Azure WCF服務,我從Javascript調用。然而,當我打電話給我的WCF服務從JavaScript,我收到以下錯誤: - 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

回答

0

爲什麼使用POST動詞而不是GET動詞?您的方法名稱暗示它是隻讀冪等資源。

+0

更改它以獲取接口定義和調用。但仍然有同樣的錯誤。 – user1216839 2012-03-04 14:52:09

0

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

您可能還想勾搭Fiddler並確保發送正確的東西。通常在JQuery中,您將傳遞數據作爲對象,而不是預先序列化的JSON字符串,因此也可能導致問題。