Self - hosted WCF server and SSL

Posted by jitm on Stack Overflow See other posts from Stack Overflow or by jitm
Published on 2010-06-16T10:28:07Z Indexed on 2010/06/16 10:33 UTC
Read the original article Hit count: 402

Filed under:
|
|

Hello, There is self - hosted WCF server (Not IIS), and was generated certificates (on the Win Xp) using command line like

 makecert.exe -sr CurrentUser -ss My -a sha1 -n CN=SecureClient -sky exchange -pe
 makecert.exe -sr CurrentUser -ss My -a sha1 -n CN=SecureServer -sky exchange -pe

These certificates was added to the server code like this:

serviceCred.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine,
                            StoreName.My, X509FindType.FindBySubjectName, "SecureServer");



serviceCred.ClientCertificate.SetCertificate(StoreLocation.LocalMachine,
                            StoreName.My, X509FindType.FindBySubjectName, "SecureClient");

After all previous operation I created simple client to check SSL connection to the server.

Client configuration:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IAdminContract" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="TransportCredentialOnly">
                      <transport clientCredentialType="Basic"/>
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://myhost:8002/Admin" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IAdminContract" contract="Admin.IAdminContract"
                name="BasicHttpBinding_IAdminContract" />
        </client>
    </system.serviceModel>
</configuration>

Code:

Admin.AdminContractClient client = new AdminContractClient("BasicHttpBinding_IAdminContract");
            client.ClientCredentials.UserName.UserName = "user";
            client.ClientCredentials.UserName.Password = "pass";
            var result = client.ExecuteMethod()

During execution I receiving next error:

  The provided URI scheme 'https' is invalid; expected 'http'.\r\nParameter name: via

Question: How to enable ssl for self-hosted server and where should I set - up certificates for client and server ? Thanks.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf