【发布时间】:2017-01-23 15:23:24
【问题描述】:
我正在实现一个需要使用 Json 对象的 WCF 服务。到目前为止,这是有效的。现在,我希望服务只接受 https,所以不接受 http。
对于这两个要求,我找到了几个我已经测试过并且似乎有效的示例。但是我无法将这两个要求集成到一个配置文件中。
这是我的服务配置:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="serviceBehavior" name="SMApi.SApi">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
bindingConfiguration="" contract="SMApi.ISApi" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<!-- / -->
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<!-- / -->
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<!-- / -->
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
<!-- / -->
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="false"/>
</system.webServer>
</configuration>
【问题讨论】:
-
尝试在
webHttpBinding上将安全模式设置为传输。为此,您需要在配置中添加绑定配置部分。