tags:

views:

239

answers:

1

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.

A: 

Try change

<security mode="TransportCredentialOnly">

to

<security mode="Transport">

and let us know if that makes any improvements. This should make your client allows HTTPS connections.

David Christiansen
After this changes I received :An error occurred while making the HTTP request to https://myhost:8002/Admin. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.
jitm
Can you update post with your server's servicemodel config
David Christiansen
David Christiansen
I have no server configurations in xml file. all configurations was written in the c# code :( ...
jitm
Could you post simple xml for config server, I should check server code where was configure in c# code?
jitm