Azure 托管 WCF azure 活动目录身份验证 returns 404
Azure hosted WCF azure active directory authentication returns 404
我是 WCF 新手。我创建了 returns 文件的 WCF 方法。我将它部署到 azure App Service 并且当我这样调用它时它起作用了
https://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue
我为 Azure 应用服务启用了 Azure 活动目录身份验证,现在我收到 404 错误。但是针对 AAD 的身份验证有效 - 如果我没有在用户中被烧毁,我将被重定向到登录页面。
我尝试搜索 SO 和 google,但我无法弄清楚我做错了什么,或者是否无法使用 WCF 进行这种设置。
网络配置:
<?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>
所以我发现我没有注意到,我原来的服务 url 是
http://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue
添加 azure 广告身份验证后我被重定向到的是
https://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue
因此重定向指向 HTTPS 而不是 HTTP。
可能可以将 azure 广告应用程序设置为不强制执行 HTTPS 流量,但是出于安全考虑并避免可能的 IE 区域切换问题,我在 web.config 中将 HTTPS 传输添加到我的 WCF 绑定中。这是一个很好的例子,如何做到这一点 现在它可以完美地工作。
我是 WCF 新手。我创建了 returns 文件的 WCF 方法。我将它部署到 azure App Service 并且当我这样调用它时它起作用了
https://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue
我为 Azure 应用服务启用了 Azure 活动目录身份验证,现在我收到 404 错误。但是针对 AAD 的身份验证有效 - 如果我没有在用户中被烧毁,我将被重定向到登录页面。
我尝试搜索 SO 和 google,但我无法弄清楚我做错了什么,或者是否无法使用 WCF 进行这种设置。
网络配置:
<?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>
所以我发现我没有注意到,我原来的服务 url 是
http://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue
添加 azure 广告身份验证后我被重定向到的是
https://myapp.azurewebsites.net/myService.svc/MyMethod?MyParam=MyValue
因此重定向指向 HTTPS 而不是 HTTP。
可能可以将 azure 广告应用程序设置为不强制执行 HTTPS 流量,但是出于安全考虑并避免可能的 IE 区域切换问题,我在 web.config 中将 HTTPS 传输添加到我的 WCF 绑定中。这是一个很好的例子,如何做到这一点