Friday, 31 December 2010

WCF service reference not creating correct proxy classes


I had a test project using NUnit to run unit tests for some components of a WCF service. In addition, I decided to include some integration tests that actually called a WCF service running in IIS on the localhost. To run the integration tests I created a service reference (which should generate the proxy classes) some types I had expected to find didn’t appear as proxies. The types that didn’t appear were declared as known types against the WCF service definition and all data contract attributes were correct. 

When I tried to use a type I had expected to find as a proxy class ReSharper was trying to help me out by referring me to the actual classes in the service projects, not from generated proxies. Even stranger, when I looked at the Reference.cs file (which should contain the proxy classes) the proxy classes were indeed missing but I could find declarations for the actual classes from the service projects.

To find References.cs – in the Solution Explorer, View All Files and expand the service reference.


The fact that ReSharper was helping by pointing at the service projects was the clue. Because this was a test project I had included unit tests that created instances of classes from the service projects and as such had included references to those projects. When I added the service reference it looks like the actual service classes were used in preference to creating proxies.

I removed the references to the service projects, commented out code that needed those references and then re-added the service reference. The proxies were generated correctly.

The moral of the story is, don’t add references to the actual service projects as well as service references to the same code. It’s a good idea to run integration tests in a separate project so the references and service references don’t trip over each other.

Friday, 31 December 2010