Creating Certificates for Bot Framework apps hosted on Service Fabric

I decided to host a bot framework application over service fabric. Creating a regular Bot Framework app is relatively simple using the provided Visual Studio template and hosting in a free tier website service in Azure.

When using service fabric, even on a local test environment we will need to have a certificate for using external channels like Facebook, Skype or Cortana. This approach is also very useful if someone prefers to debug metadata on Facebook or Cortana messages, which is rather under-documented.

The certificate is needed for the https endpoint, in case an invalid (or expired) certificate the connection will not be established.

Once we have a domain name, we can use (as an example) Let's Encrypt to create the certificates for free. I used one of the suggested web tool: SSL For Free to generate the cert. The key step here is to use Chrome as the browser. At the time of the writing Edge generated invalid certificates. When the domain name is validated we will need to run the following command to generate a pfx file, so later we can install it into our cert store.

Find out more


Service Fabric - Https and Http

There are several good resources to set up Service Fabric Https endpoints. I would reference here HTTP & HTTPS in Service Fabric Web API which describes all the necessary steps to set up Http and Https endpoints. Doing the work manually will result pretty similar, except for the last step, which can trick the usual developer:

new ServiceInstanceListener(serviceContext =>
new OwinCommunicationListener(Startup.ConfigureApp, serviceContext, ServiceEventSource.Current, endpoint));

When you add one ServiceInstanceListener (Http or Https) the endpoint will open, but adding multiple, the code above will fail to open any endpoints.

The key step here is an optional parameter in the constructor of ServiceInstanceListener. Unless the name specified we will not be able to open multiple endpoints. So one suggestion to correct the above code:

Find out more


Reading list

I have read a couple of books over the last years. Let me collect some of the books I liked the most:

  • CLR via C#, By: Jeffrey Richter

  • Algorithms in a Nutshell, By: George T. Heineman; Gary Pollice; Stanley Selkow

  • Clean Code, By: Robert C. Martin

  • The Clean Coder, By: Robert C. Martin

  • Dependency Injection in .NET, By: Mark Seemann

  • The Art of Unit Testing, By: Roy Osherove

  • Angular 2 Development with TypeScript, By: Yakov Fain and Anton Moiseev

Find out more


SingleOrDefault - Safe

On the other day I ran into a task to return the only one element of a list/enumeration if exists, and I had to do it in a performant way. The list or enumeration could have any number of not null items. Using FirstOrDefault is not an option as it does not restrict having multiple items in the list. SingleOrDefault could be a choice, but it throws an exception in the case of multiple items. Handling the exception was not an option.

One solution could be to call Count and only return the first item if the value is one. The problem with this solutions is enumerating through the items to get the count for enumerable types. A better solution is to write a new SingleOrDefault extension methods to handle list and enumeration types.

Implementation

The following method is an extension of IEnumerable<T>

Find out more