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
定義的處理程序,但它仍然無法正常工作。