无法通过https

时间:2017-06-27 20:43:41

标签: c# wcf https windows-services

我设置了一个由Windows服务托管的WCF应用程序。我让这个工作正常,我可以转到http://127.0.0.1:1214导航到它。这是配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="NetworkPrintClient.PrintWebService" behaviorConfiguration="PrintServiceBehavior">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://127.0.0.1:1214/"/>
                    </baseAddresses>
                </host>
                <endpoint address="" binding="wsHttpBinding" contract="NetworkPrintClient.IPrintWebService" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="PrintServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="False"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

现在我想在https://127.0.0.1:1214处访问此内容。在阅读了几篇关于这样做的文章后,我最终得到了下面的配置。但是,我无法再浏览应用程序了。我只是得到了一个&#34;这个网站无法到达&#34; Chrome中出错。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="NetworkPrintClient.PrintWebService" behaviorConfiguration="PrintServiceBehavior">
                <host>
                    <baseAddresses>
                        <add baseAddress="https://127.0.0.1:1214/"/>
                    </baseAddresses>
                </host>
                <endpoint address="" binding="webHttpBinding" contract="NetworkPrintClient.IPrintWebService" behaviorConfiguration="HttpBehavior" bindingConfiguration="PrintServiceHttpsBinding"/>
                <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="PrintServiceBehavior">
                    <serviceMetadata httpsGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="False"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="HttpBehavior">
                    <webHttp />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <bindings>
            <webHttpBinding>
                <binding name="PrintServiceHttpsBinding">
                    <security mode="Transport">
                        <transport clientCredentialType="None" />
                    </security>
                </binding>
            </webHttpBinding>
        </bindings>
        <protocolMapping>
            <add binding="webHttpBinding" scheme="https"/>
        </protocolMapping>
    </system.serviceModel>
</configuration>

我过去的文章是here。我在底部做了关于制作证书并将其映射到我的IP和端口的部分。我也试图让这个与#34; localhost&#34;和我的实际IP地址。谁能看到我做错了什么?

1 个答案:

答案 0 :(得分:3)

  1. 您必须创建一个自动托管到localhost的证书,您可以在powersheel中使用此命令行 New-SelfSignedCertificate -DnsName“localhost”,“localhost”-CertStoreLocation“cert:\ LocalMachine \ My”执行时将生成证书的指纹保持关联到这样的端口“B80BE75765AA5739EAC63AAF67C32E5A3625FF19 “
  2. 在窗口类型“证书”中,单击管理计算机证书并将证书从个人\证书复制到受信任的根证书颁发机构\证书
  3. 将证书哈希(指纹与端口关联) - netsh http add sslcert ipport = 0.0.0.0:{0} certhash = {1} appid = {2} certstore = MY 0 - port - 1 - (证书生成的指纹)2 - {555b2e5f-4877-459b-bff2-60bb25898455}(GUID)