Troncoso
Troncoso

Reputation: 2463

Can't access WCF service through https

I setup a WCF application to be hosted by a Windows service. I got this to work correctly and I can navigate to it by going to http://127.0.0.1:1214. Here is the configuration:

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

Now I'd like to make this accessible at https://127.0.0.1:1214. After reading several articles about doing this, I end up with the config below. But, I can't browse to the application anymore. I just get a "This site can't be reached" error in 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>

The article I used to get this far is here. I did the part at the bottom about making the certificate and mapping it to my IP and port. I also tried to get this to work with "localhost" and my actual IP address. Can anyone see what I'm doing wrong?

Upvotes: 2

Views: 1492

Answers (1)

Deyvison Souto
Deyvison Souto

Reputation: 157

  1. You must to create a certificate selfhosted to localhost, you can use this command line in powersheel New-SelfSignedCertificate -DnsName "localhost", "localhost" -CertStoreLocation "cert:\LocalMachine\My" when you execute is gonna generate the thumbprint of certificate keep to associate to the port something like this "B80BE75765AA5739EAC63AAF67C32E5A3625FF19"
  2. in window type "certificates" and click manage computer certificates and copy the certificate from personal\certificates to trusted root certification authorities\certificates
  3. associate the certificate hash (thumbprint to the port) - netsh http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={2} certstore=MY 0 - port - 1 - (the thumbprint generated by the certificate) 2 - {555b2e5f-4877-459b-bff2-60bb25898455} (GUID)

Upvotes: 3

Related Questions