簡體   English   中英

在 HTTPS 上托管 WCF Windows 服務

[英]Host WCF Windows Service on HTTPS

我正在嘗試在 https 上配置使用 Windows 服務托管的 WCF 服務。

該服務適用於 http,但似乎不適用於 https。

配置文件(適用於 http):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment  aspNetCompatibilityEnabled="false" />

    <!-- Set up Custom Behaviors -->
    <behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetUrl="true" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <!-- Set up the binding configuration  -->
    <bindings>
      <wsHttpBinding>
       <binding name="HttpsSOAPBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
        <binding name="HttpSOAPBinding">
          <security mode="None" />
        </binding>
      </wsHttpBinding>
    </bindings>

    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService"
               behaviorConfiguration="CalculatorServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://server_name:8080/ServiceModelSamples/service"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="wsHttpBinding"
                  bindingConfiguration="HttpSOAPBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    
  </system.serviceModel>
</configuration>

我更改了 https 的以下設置:

  • 將 wsHttpBinding 端點綁定配置更改為 HttpsSOAPBinding
  • 將基地址更改為 http s ://server_name:8080/ServiceModelSamples/service"
  • 將 mex 端點綁定更改為 mexHttpsBinding

我還將端口 8080 附加到 ssl 證書。

netsh http 顯示 sslcert

 IP:port                      : 0.0.0.0:8080
 Certificate Hash             : 12ea34b0e1e46b12346ae04834cf1deaefb52f33
 Application ID               : {cba53ac4-6ecf-4a49-8aq3-z6c61e2ce9a1}
 Certificate Store Name       : (null)
 Verify Client Certificate Revocation : Enabled
 Verify Revocation Using Cached Client Certificate Only : Disabled
 Usage Check                  : Enabled
 Revocation Freshness Time    : 0
 URL Retrieval Timeout        : 0
 Ctl Identifier               : (null)
 Ctl Store Name               : (null)
 DS Mapper Usage              : Disabled
 Negotiate Client Certificate : Disabled

有什么遺漏嗎?

所以你表示你不確定端口是否打開。 我會嘗試使用 telnet 命令來查看您的端口是否可以從您嘗試訪問服務的機器訪問。 為此,您需要在命令提示符下使用以下命令。

telnet 192.168.1.1 8080

現在您需要用您的服務器 IP 地址替換 192.168.1.1。


您可能想嘗試找出的另一件事是您的問題是否與防火牆有關,或者服務是登錄到服務器本身並嘗試在該服務器上本地訪問您的服務。

http://localhost:8080/ServiceModelSamples/service

當然,這是假設您有能力登錄到服務器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM