C# Can';无法通过https访问WCF服务

C# Can';无法通过https访问WCF服务,c#,wcf,https,windows-services,C#,Wcf,Https,Windows Services,我将WCF应用程序设置为由Windows服务托管。我让它正常工作,我可以通过转到导航到它。以下是配置: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name="NetworkPrintClient.PrintWebService" behavio

我将WCF应用程序设置为由Windows服务托管。我让它正常工作,我可以通过转到导航到它。以下是配置:

<?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>

. 在阅读了几篇关于这方面的文章之后,我最终使用了下面的配置。但是,我不能再浏览应用程序了。我刚刚在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>

. 我在底部做了关于制作证书并将其映射到我的IP和端口的部分。我还试图让它与“localhost”和我的实际IP地址一起工作。有人能看出我做错了什么吗

  • 您必须创建自托管到localhost的证书,您可以在PowerShell中使用此命令行 新的自签名证书-DnsName“localhost”,“localhost”-CertStoreLocation“cert:\LocalMachine\My”执行时将生成证书的指纹,以保持与端口关联,如“B80BE75765AA5739EAC63AAF67C32E5A3625FF19”
  • 在窗口中键入“certificates”并单击管理计算机证书,然后将证书从personal\certificates复制到受信任的根证书颁发机构\certificates
  • 将证书散列(指纹与端口关联)netsh http add sslcert ipport=0.0.0:{0}certhash={1}appid={2}certstore=MY0-端口-1-(由证书生成的指纹)2-{555b2e5f-4877-459b-bff2-60bb25898455}(GUID)

  • 您是否尝试过使用WCF测试客户端访问您的服务?-我发现这在某些情况下很有帮助。另外,我建议您从上面的工作版本开始,然后在所有剩余的部分使用一块一块的胶水,同时确保每个步骤仍然有效。非常感谢您的帮助!我相信我错过了第二步。我按照我引用的指南回顾了我所做的工作,并没有将证书移动到受信任的根目录。做了那件事之后,一切都像预期的那样进行着。