简体   繁体   English

在 HTTPS 上托管 WCF Windows 服务

[英]Host WCF Windows Service on HTTPS

I am trying to configure a WCF service hosted using windows service on https.我正在尝试在 https 上配置使用 Windows 服务托管的 WCF 服务。

The service works with http but does not seem to work on https.该服务适用于 http,但似乎不适用于 https。

Configuration file (works for http):配置文件(适用于 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>

I changed the following settings for https:我更改了 https 的以下设置:

  • Change wsHttpBinding endpoint binding configuration to HttpsSOAPBinding将 wsHttpBinding 端点绑定配置更改为 HttpsSOAPBinding
  • Change base address to http s ://server_name:8080/ServiceModelSamples/service"将基地址更改为 http s ://server_name:8080/ServiceModelSamples/service"
  • Change mex endpoint binding to mexHttpsBinding将 mex 端点绑定更改为 mexHttpsBinding

I have also attached port 8080 to ssl certificate.我还将端口 8080 附加到 ssl 证书。

netsh http show sslcert 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

Is there anything missing?有什么遗漏吗?

So you indicated that that you aren't sure the port is open.所以你表示你不确定端口是否打开。 I would try using the telnet command to see if your port is accessible from the machine you are trying to access the service from.我会尝试使用 telnet 命令来查看您的端口是否可以从您尝试访问服务的机器访问。 For this you will need to use the following command in a command prompt.为此,您需要在命令提示符下使用以下命令。

telnet 192.168.1.1 8080

Now you will want to replace 192.168.1.1 with your servers IP address.现在您需要用您的服务器 IP 地址替换 192.168.1.1。


Another thing you may want to try to find out if your issue is with a firewall or the service would be to log on to the server itself and attempt to hit your service locally on that server.您可能想尝试找出的另一件事是您的问题是否与防火墙有关,或者服务是登录到服务器本身并尝试在该服务器上本地访问您的服务。

http://localhost:8080/ServiceModelSamples/service http://localhost:8080/ServiceModelSamples/service

Of course this is assuming that you have the ability to log onto the server.当然,这是假设您有能力登录到服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM