Verify that the current user is granted access in the appropriate allowAccounts section of SMSvcHost.exe.config

Quick tip that maybe will save others time:

In Windows 7 ( and maybe Vista) when hosting a WCF Service in a console application AS A USER and not as administrator, you might get an exception telling you that you don't have access to register with the net.tcp port sharing service.

To resolve this problem:

  • Download PsGetSid ( this will give you the Security Identifier - SID for your user or user group )

  • Find and open SMSvcHost.exe.config ( usualy in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\SMSvcHost.exe.config or c:\Windows\Microsoft.NET\Framework\v4.0.30319\SMSvcHost.exe.config )

  • Run psgetsid.exe to get the SID ( should look something like this S-1-5-21-1754548885-2506776180-2303324228-4659 )

  • By default the SMSvcHost.exe.config contains a section which has a child which has a child. The IMPORTANT part if you are using an editor that does not do syntax highlight for XML - THE ABOVE SECTION IS COMMENTED by DEFAULT so adding child has not effect.

  • YOU NEED TO ADD A NEW SECTION with it's children sections to make it work ( or uncomment the existing one and removing the // comments which are not valid xml ).

  • Restart the net.tcp portsharing service and you are good to go.

In the end you should have something like this:

 1 < ?xml version="1.0" encoding="utf-8"?>
 2 <!-- The configuration file for SMSvcHost.exe -->
 3 <configuration>
 4     <runtime>
 5         <gcconcurrent enabled="false" />
 6     </runtime>
 7     <system.serviceModel>
 8         <diagnostics performanceCounters="Off" etwProviderId="{f18839f5-27ff-4e66-bd2d-639b768cf18b}"/>
 9     </system.serviceModel>
10  <system.serviceModel.activation>
11         <net.tcp listenBacklog="10" maxPendingConnections="100" maxPendingAccepts="2" receiveTimeout="00:00:10" teredoEnabled="false">
12             <allowaccounts>
13                 <add securityIdentifier="S-1-5-21-1754548885-2506776180-2303324228-4659"/>
14             </allowaccounts>
15         </net.tcp>
16     </system.serviceModel.activation>
17 </configuration>

Also you might need to grant access to the user to register as a listener for an url:

netsh http add urlacl url=http://+: <port>/MyUri user=DOMAIN\user

I have to admin the most of the time i've spent on this issue was because i was modifying the commented section in the the config xml.

New Github account

I’ve opened a Github account where i keep some stuff I've been playing with recently. At the moment is mostly related to doing DDD with CQRS and Event Sourcing.

I’ve created a sample project to demonstrate the concepts. Here is a short description of the sample:

Sample project demonstrating CQRS & Event Sourcing

The sample uses the following projects from Jonathan Oliver

  • EventStore
  • NanoServiceBus
  • CommonDomain
  • StorageAccess

For more information on CQRS and Event Sourcing http://cqrsinfo.com/

A short description of the projects in the sample:

a. Write Side

1. Sample.DomainModel   
    - the domain model for the sample   
    - this model is persisted using event sourcing and does not need to handle reads ( queries )   
    since they are done on the read side.   
    - the resulting event stream is the "source of truth" data. 

2. Sample.AppService   
    - the handlers for the commands our domain knows to execute 

3. Sample.AppServiceHost   
    - infrastructure for wiring up the command handlers to NanoServiceBus   
    - this is the actual instance of the service that needs to be running for the write side to process   
    commands. 

b. Read Side

1. Sample.ReadModel   
    - the read model on witch queries are executed   
    - this model should be mapped as close as possible to the views   
    - this model can be regenerated from the event stream 

2. Sample.Denormalizer   
    - the event handlers for the domain events that are published by the DomainModel on the Write Side   
    - this handlers keep the read model in sync with the event stream   
    - a better name for it is welcome 

3. Sample.DenormalizerHost   
    - infrastructure for wiring up the event handlers to NanoServiceBus   
    - this process needs to run for the read side to be updated. 

c. Infrastructure

1. Sample.Messages   
    - definitions for commands and events that are handled or published by the Domain Model   
2. Sample.Client.Web   
    - ASP.NET MVC3 application that demonstrates how to integrate the Write Side & the Read Side in an application. 

TODO

  • Add more complex objects to the domain
  • Review transaction management on integration points
  • use ConfOrm for mapping the read model

I’d be glad if other shared their comments on the code there.

Hardware-based brute force attacks

I've found this image in a PDF presentation document and i feel like sharing:

Hardware-based brute force attacks

Source: scrypt-slides by Colin Percival

Log4Net not logging errors to db

This is a short post about logging errors to db with log4net.

I've recently been bitten by a bug or better said miss configuration of log4net. I'm using log4net with database logging and file logging in a project and i was wandering why there are no error messages logged in the db when they are logged in the log files configured.

At one point it hit me: Transactions. Good ol` transactions. Distributed ones.

In this project i use a mix of NServiceBus based windows services and WCF services. They all use a variation of the Unit Of Work pattern to manage the atomicity of the operations. Since we use MSMQ messaging and NHibernate sessions they all fall under a distributed transaction. By default log4net AdoNet appender also uses a transaction to insert the log message in the db. And this transaction was enlisting in the ambient distributed transaction. Now in case of an error the unit of work get's aborted and the transactions get rolled back. This also includes log4net's transaction.

The solution is simple after you figure out the problem. Just add in the configuration section for the ADONetAppender. Ex:

1 <appender name="MySQLAppender" type="log4net.Appender.ADONetAppender">
2     <usetransactions value="false"/>
3     <!-- rest of the configuration -->
4 </appender>

Context Matters

The next paragraph made me remember of a lot of hours of discussions with various developers:

If you’re arguing with me that NHibernate is the wrong tool because you’re writing reporting applications, just say “I write reporting applications.” And when I say “I think NHibernate is the best tool for persisting domain models,” I should probably talk about that specific context. And definitely, when you say “Linq to Sql rocks!” you better follow that up with “for applications with simplistic domain models.” (source: Context Matters)

If more developers would think like this we would probably have better tools with better acceptance in a lot less time.