Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self - hosted WCF server and SSL

Tags:

c#

ssl

wcf

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.

like image 208
jitm Avatar asked Jun 16 '10 10:06

jitm


People also ask

What is self hosting in WCF?

This is referred to as a self hosting WCF service, the exact meaning of Self Hosted is that it hosts the service in an application that could be a Console Application or Windows Forms and so on. Earlier we saw what a WCF Service is in the . Net environment. We can host a WCF service in IIS and a Windows service also.

Where can a WCF service be hosted?

WCF services can be hosted in any managed application. This is the most flexible option because it requires the least infrastructure to deploy. You embed the code for the service inside the managed application code and then create and open an instance of the ServiceHost to make the service available.

What is WCF service?

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.


1 Answers

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.

like image 126
David Christiansen Avatar answered Oct 22 '22 11:10

David Christiansen