Visual Studio 2008 has Unit testing support built into it, whereby you can define batches of unit tests and run them as part of your build process.

However, when I tried writing a test against an asmx Web Service, I could not get it to work using the .asmx (endpoint/page) request.

I used a web request style unit test:

[TestMethod()]
[HostType(“ASP.NET”)]
[AspNetDevelopmentServerHost(“C:\\projects\\fooService”, “/”)]
[UrlToTest(“http://localhost:62534/fooService)%5D”>http://localhost:62534/fooService”)]

public void GetFooTest()
{
      fooService svc = new fooService();
     foo.doSomething();
    Assert(blah, blah);

Unfortunately, this does not work and most likely you will get a 404.
I got this error when I ran my unit test:

Could not connect to the Web server for page ‘http://localhost:62534/fooService’. The remote server returned an error: (404) Not Found.. Check that the Web server is running and visible on the network and that the page specified exists.

I tried a few hacks like adding a default page to the service project and specifying that in the UrlToTest attribute, etc. but to no avail.

Finally, I resorted to just adding a Service Reference to the target and removed the three web attributes. This means that my service class is instantiated directly and not through a web service request but honestly I don’t care about the transport part. I’m mainly interested in testing functionality anyway.

Hope this post helps…

I came across this error while serializing an entity class using an XmlSerializer, and realized one of the causes for the error is when the class being serialized does not have a default (empty) constructor.
I had added a parameterized constructor to provide some syntactic sugar, and started getting the error.

So, if you get this type of error, define a default constructor to fix the serialization error.
public class foo()
{
     public foo () { }
}

Note: You can pinpoint the class by going through the chain of Inner Exceptions.

Just wanted to write about a baffling problem I came across while debugging my web service in Visual Studio 2008.
I was running in debug mode and when I called a method that I had set up breakpoints in, I kept getting an error stating “There is no source code available at this location”.

As always, one should take a step back and try to understand the issue.
The message seemed to indicate that the assembly debug symbols/information and code were out of sync. To verify that, I made a change to the names to one of my web service methods and sure enough, the (auto-generated) debug page for an asmx still showed the old method name. Clearly, my code was not being built.
I fixed the problem by checking the Build checkbox (which somehow got unchecked) in the Solution – Properties – Configuration VS dialog.
As a side, always ensure that your assemblies are built the way you assume they are. Maybe, even delete the dll files to be sure and then do a build/debug and ensure that, if you’re using Internet Explorer to debug), the “Show friendly errors” and “Disable debugging” is off.