2016-09-29 130 views
0

我是WCF的新手。我創建了返回文件的WCF方法。我其部署到Azure應用服務和它的工作時,我把它叫做這樣Azure託管的WCF Azure Active Directory身份驗證返回404

https://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue 

比我開啓蔚藍應用服務Azure的Active Directory身份驗證,現在我得到404錯誤。但是,對AAD進行身份驗證的作品 - 我被重定向到登錄頁面,如果我沒有在用戶中燒錄。

我那麼搜索和谷歌,我想不出我做錯了什麼,或者如果它僅僅是不可能建立這種方式與WCF。

Web配置:

<?xml version="1.0"?> 
<configuration> 

    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> 
    </appSettings> 
    <system.web> 
    <customErrors mode="Off"/> 
    <compilation targetFramework="4.5.2"/> 
    <httpRuntime targetFramework="4.5.2"/> 
    <httpModules> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/> 
    </httpModules> 
    </system.web> 

    <system.serviceModel> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    <bindings> 
     <webHttpBinding> 
     <binding name="ServiceWebBindingName" transferMode="Streamed" maxReceivedMessageSize="2147483647" > 
      <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" /> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="DefaultRestServiceBehavior"> 
      <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped" automaticFormatSelectionEnabled="false"/> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="My.App.Service"> 
     <endpoint address="myService.svc" 
       binding="webHttpBinding" 
       bindingConfiguration="ServiceWebBindingName" 
       behaviorConfiguration="DefaultRestServiceBehavior" 
       name="FileManagerServiceEndpoint" 
       contract="My.App.IService"/> 
     </service> 
    </services> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="ApplicationInsightsWebTracking"/> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" 
     preCondition="managedHandler"/> 
    </modules> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <directoryBrowse enabled="false"/> 
    <validation validateIntegratedModeConfiguration="false"/> 
    </system.webServer> 

</configuration> 
+0

你檢查了這個帖子,談論wcf + AAD集成https://dzone.com/articles/exercise-3-securing-wcf – Aravind

+0

我做了,在文章中,他們沒有使用設置認證的azure主機,但是如果我正確地理解了這些內容,就可以在代碼中做所有事情 – Evlo

+0

啊,認證部分的代碼做.. – Aravind

回答

0

所以我發現我沒有注意到,那我原來的服務URL是

http://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue 

和一個我是加入蔚藍廣告驗證後重定向到了

https://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue 

因此重定向到HTTPS而不是HTTP。

這可能是可以設置蔚藍ad應用不強制HTTPS流量,但在安全的精神,避免我添加HTTPS傳輸到我的WCF在web.config中綁定IE瀏覽器可以切換區的問題。這裏是一個很好的例子,如何做到這一點How to enable HTTPS on WCF RESTful Service?它現在完美無瑕。

相關問題