【发布时间】:2021-06-04 05:58:52
【问题描述】:
我有一个 WCF 服务,它使用 ServiceHost 类托管在 exe 中。我称它为“网络服务”,因为它通过 https 进行侦听,所以我可以从网络浏览器 ping 它。 (对不起,如果我的所有术语都不准确。)
我想为此网络服务启用 HSTS。 我发现我可以通过将其放入 Web.config 来启用它:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000"/>
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
<outboundRules>
<rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
<match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
</conditions>
<action type="Rewrite" value="max-age=31536000" />
</rule>
</outboundRules>
</rewrite>
但我没有 Web.config,因为该服务未托管在 IIS 中。 我试图将其添加到 system.ServiceModel 部分但无效。 我不确定是否可以在没有 IIS 支持的情况下处理 system.webServer 部分。 如果没有 IIS(或 Apache),我也不确定 HSTS 是否是一个有效的概念。
目前看的所有文章,都只描述了IIS场景。
https://www.hanselman.com/blog/how-to-enable-http-strict-transport-security-hsts-in-iis7
https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/hsts
https://www.forwardpmx.com/insights/blog/the-ultimate-guide-to-hsts-protocol/
所以我的问题是:如何在这种情况下启用 HSTS?
编辑: 我的服务模型配置(编辑以遮盖我们的产品名称)
<system.serviceModel>
<services>
<service behaviorConfiguration="AServiceBehavior" name="something.RemoteAccess.WebAccess.A.Core.A">
<endpoint address="" behaviorConfiguration="AEndpointBehaviour" binding="basicHttpBinding" bindingConfiguration="secureBasicHttpBinding" name="A" bindingNamespace="uri:something.RemoteAccess.WebAccess.A" contract="something.RemoteAccess.WebAccess.A.IService"/>
<host>
<baseAddresses>
<add baseAddress="https://*:4510/somethingWebAccess/A"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureBasicHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="AEndpointBehaviour">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="AServiceBehavior">
<serviceMetadata httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
【问题讨论】:
-
您在 WCF 中使用了哪些绑定?您是在使用 SOAP 的 HTTP REST 功能,还是在使用 SOAP over HTTP?您可以发布您的
app.config文件以显示您的<system.serviceModel>配置吗?您是否在在代码中进行任何配置? -
基本上,您可以在 WCF 代码中访问
WebOperationContext吗? -
另外,正如您现在可能知道的那样,WCF 是......不必要的复杂,具有真正疯狂的重载术语(绑定,行为,端点,aieee!)和令人困惑的过度配置 - 我'我很高兴 WCF 死了。您是否有从 WCF 迁移到更现代、更精简的计划,例如 ASP.NET Core?
-
我无权访问 WebOperationContext。
-
我们的产品太可怕了,我看不到从 WCF 迁移的机会。 :(