C# 仅实现Json和https的Wcf服务

C# 仅实现Json和https的Wcf服务,c#,json,wcf,ssl,https,C#,Json,Wcf,Ssl,Https,我正在实现一个需要使用Json对象的WCF服务。到目前为止,这是有效的。现在,我希望服务只接受https,所以不接受http 对于这两个需求,我已经找到了两个我已经测试过的样本,它们似乎都很有效。但是,我无法将这两个需求集成到一个配置文件中 这是我的服务配置: <?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchro

我正在实现一个需要使用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>

尝试为
添加绑定配置,并将安全模式设置为传输。您需要显式地将绑定配置设置到端点

<bindings>
  <webHttpBinding name="SMApiWebhttpBinding">
    <security mode="Transport" />
  </webHttpBinding>
</bindings>

尝试将安全模式设置为在
webHttpBinding
上传输。为此,您需要在配置中添加一个绑定配置部分。
<service behaviorConfiguration="serviceBehavior" 
         name="SMApi.SApi">
  <endpoint address="" behaviorConfiguration="web" 
            binding="webHttpBinding"
            bindingConfiguration="SMApiWebHttpBinding"
            contract="SMApi.ISApi" />