【问题标题】:How To Transform my HTTP windows service to HTTPS如何将我的 HTTP Windows 服务转换为 HTTPS
【发布时间】:2022-09-23 15:33:03
【问题描述】:

我正在努力将部署在服务器上的 Windows 服务从 HTTP 传递到 HTTPS。

我们应该如何着手?

<system.serviceModel>
<!--Conf HTTP-->
<client>      
  
  <endpoint address=\"http://localhost/WorkflowsService\"
    binding=\"customBinding\" bindingConfiguration=\"UserNameOverTransportBindingConfiguration\"
    contract=\"OmmoComponents.Workflows.Common.Contracts.IWorkflowsService\"
    name=\"WorkflowsServiceEndPoint\"/>      
  
  
  <endpoint address=\"http://localhost/OMVGestionService\" binding=\"customBinding\"
    bindingConfiguration=\"UserNameOverTransportBindingConfiguration\"
    contract=\"OmmoOMV.Gestions.Common.Contracts.IOMVGestionService\"
    name=\"OMVGestionServiceEndPoint\" />
  
  <endpoint address=\"http://localhost/OMVControlesService\" binding=\"customBinding\"
    bindingConfiguration=\"UserNameOverTransportBindingConfiguration\"
    contract=\"OmmoOMV.Controles.Common.Contracts.IOMVControlesService\"
    name=\"OMVControleServiceEndPoint\" />
  
  <endpoint address=\"http://localhost/OMVFacturationService\" binding=\"customBinding\"
    bindingConfiguration=\"UserNameOverTransportBindingConfiguration\"
    contract=\"OmmoOMV.Facturation.Common.Contracts.IOMVFacturationService\"
    name=\"OMVFacturationService\" />
  
  <endpoint address=\"http://localhost/SecurityServices\" binding=\"customBinding\"
    bindingConfiguration=\"DefaultBindingConfiguration\" contract=\"OmmoComponents.Security.Common.Contracts.ISecurityServices\"
    name=\"SecurityServicesEndPoint\" />
</client>
</system.serviceModel>

我使用新的基地址为 HTTPS Windows 服务添加了一个新的端点配置,以便复制现有配置

   <service name=\"EntityManagementService\">
    <endpoint address=\"\" 
              binding=\"customBinding\" 
              bindingConfiguration=\"UserNameOverTransportBindingConfiguration\" 
              contract=\"OmmoComponents.EntityManagement.Common.Contracts.IEntityManagementService\" 
              name=\"EntityManagementServiceEndPoint\" />
    <endpoint address=\"\" 
              binding=\"customBinding\" 
              bindingConfiguration=\"UserNameOverTransportBindingConfigurationExt\" 
              contract=\"OmmoComponents.EntityManagement.Common.Contracts.IEntityManagementService\" 
              name=\"EntityManagementServiceExtEndPoint\" />
    <host>
      <baseAddresses>
        <add baseAddress=\"http://localhost:7190/EntityManagementService\" />
        <add baseAddress=\"https://localhost:7191/EntityManagementService\" />
      </baseAddresses>
    </host>
  </service>
  • 我复制现有配置并使用 HTTPS 进行更改。请看我最近的修改

标签: c# http wcf https


【解决方案1】:

也许我们可以添加一个 http 端点,如下所示:

<system.serviceModel>
    <services>
      <service behaviorConfiguration="mybehavior" name="WcfService1.Service1">
        <endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev"></endpoint>
        <endpoint address="" binding="webHttpBinding" contract="WcfService1.IService1" behaviorConfiguration="webbev" bindingConfiguration="myhttpsbinding"></endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:11010"/>
            <add baseAddress="https://localhost:11011"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="myhttpsbinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" sendTimeout="00:10:00" receiveTimeout="00:10:00">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mybehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webbev">
          <webHttp />
        </behavior>
      </endpointBehaviors>
</behaviors>

此配置可在 http 和 https 上正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-10
    • 2011-12-04
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    相关资源
    最近更新 更多