views:

284

answers:

2

Problem: Trying to reference a .NET 2.0 web service project from my VS unit testing project.

Right click on the References folder in the unit test project -> Add Reference. The .NET 2.0 web service is NOT listed in the listbox of projects available to reference.

I know this usecase is possible; I have previously successfully referenced (in other solutions) a .NET 3.5 web service from a .NET 3.5 unit testing project.

The idea is to unit test all the public methods found in the classes alongside my .asmx. I have abstracted away all business logic away from the .asmx file itself into .cs files in a subdirectory in the web service project. So the idea here is to test the classes that perform the business logic, the web service itself (handling an HTTP request).

Configuration:

  • Visual Studio 2008
  • VS Unit testing project at .NET 3.5 compatibility
  • Web service project at .NET 2.0 compatibility
  • Solution file at version 9.

Question: Any ideas why Visual Studio 2008 won't let me reference a .NET 2.0 web serivce from a .NET 3.5 unit testing project?

+1  A: 

No. Never make a reference directly to the web service project. You want to add a "Web Reference".

John Saunders
Thanks John, I often learn from and appreciate all your answers on SO. The kicker here is that I have previously done this direct referencing into a v3.5 solution, and it works perfectly! The unit testing assembly should be calling into the web service's classes and public methods. Sounds like you're against the idea of directly referencing the business layer of the web service assembly. I'd be interested to hear why/not. Thanks!
p.campbell
The business layer doesn't belong in the web service assembly. The only thing that belongs there is the service. The rest should be in separate assemblies, and would, of course, be testable.
John Saunders
A: 

This question was a little more narrow that previously described.

The end result was that:

  • the web services project was actually a Web Site Project (!) with a single .asmx file. I was stunned to make that realization. Doh!

  • The project was re-created from scratch as a Web Service Project. All the logic was moved to an external assembly on John's advice in the comments.

p.campbell