首页 > 解决方案 > 在 localhost 上为 https/SSL 配置 wcf 服务

问题描述

编辑:已经修复它...我只需要更改项目属性并启用 SSL。


原始问题:

我正在开发一个 WCF 服务,该服务将托管在具有 SSL 证书的 IIS 服务器中。

当我将代码上传到服务器(具有所有证书)时,我的代码工作得非常好,但是由于我将安全性添加到 Web 配置中,当我尝试在本地机器上调试它时它会崩溃。

我将以下 Web 配置用于不需要 SSL 证书的 SOAP 服务和需要它的 REST 服务:

<configuration>
...
    <bindings>
      <basicHttpBinding>
        <binding name="SOAPEndPoint" />
      </basicHttpBinding>
      <webHttpBinding>
        <binding name="SecureBinding" >
          <security mode="Transport"></security>
        </binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="xxx.WS">
        <endpoint address="SOAP" binding="basicHttpBinding" name="SOAPEndPoint" contract="xxx.ISerSoap" />
        <endpoint address="api" binding="webHttpBinding" name="RESTEndPoint" contract="xxx.ISerRest" behaviorConfiguration="RestBehavior" bindingConfiguration="SecureBinding"/>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="RestBehavior">
          <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="true" />
  </system.webServer>

</configuration>

我希望能够调试它,而无需在每次在调试期间打开它时更改 Web 配置,并且如果我必须将其上传到服务器。

当我在调试模式下调用它时,有人知道绕过安全性的方法吗?或者在我的本地主机上添加对 https 的支持的简单方法?

标签: c#wcfconfig

解决方案


只是发现解决方案是在项目属性窗口上激活“SSL Enabled = true”。


推荐阅读