2014-02-08 76 views
0

我已將REST服務遷移到Azure網站,但它始終以400.0 Bad Request錯誤(錯誤代碼爲零)返回。400.0對Azure網站上的REST API的錯誤請求

該服務在本地運行,並且在Web角色中運行時完美運行。進入網站後,它開始回到400.0錯誤。

我的web.config:

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </modules> 
</system.webServer> 
<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
    <standardEndpoints> 
     <webHttpEndpoint> 
      <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" /> 
     </webHttpEndpoint> 
    </standardEndpoints> 
</system.serviceModel> 

我已經ASP.NET兼容性在我的班級設置:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] 
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)] 
public class BookingService { ... } 

和Global.asax.cs中定義的正確的路由:

private void Application_Start (object sender, EventArgs e) { 
    RouteTable.Routes.Add(new ServiceRoute("booking/service", new WebServiceHostFactory(), typeof(BookingService))); 
} 

現在,當我嘗試本地訪問REST API時,它工作正常:

http://localhost/booking/service/help 

然而,上載網絡服務爲Azure的網站和做後:

http://xxx.azurewebsites.net/booking/service/help 

它回來了400.0錯誤的請求。詳細的錯誤日誌顯示:

Request: ManagedPipelineHandler 
Notification: ExecuteRequestHandler 
Handler: System.ServiceModel.Activation.AspNetRouteServiceHttpHandler 
Error code: 0x00000000 

我在總損失。谷歌搜索沒有產生任何幫助。我試圖把以下內容web.config中:

<handlers> 
    <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="Foo.RoutingHandler" /> 
</handlers> 

,並通過擴展UrlRoutingHandler和定義VerifyAndProcessRequest定義的處理程序,但它仍然無法正常工作。

回答

0

終於發現錯誤後關閉服務一點一點。

當時的情況是:

  • RouteTable.Routes.Add補充說,創建BookingService類的對象作爲處理路線
  • BookingService有被初始化
  • 這個初始化語句失敗靜態財產(由於某種原因,這裏不提)
  • 因此,當路由服務嘗試創建BookingService類時,類的靜態初始化是第一次運行時,未能
  • 其結果是,該代碼永遠不會達到路由服務,所以服務於AspNetRouteServiceHttpHandler處理
  • 失敗如果類在運行靜態初始化失敗,而是創建對象時,它是可能的路由服務將則拋出一個更有意義的錯誤針指向問題

總之,如果你看到一個路由請求的處理程序出現故障,可以通過類代碼引起的不能加載(由於靜態初始化失敗或其他原因)。

相關問題