Tuesday, May 15, 2007

Web services deployment problems (dotnet 2.0 and VS2005)

It is very easy to write and debug the web service using VS2005, however deploying that web service to IIS has so many issues to trip you up that I'm documenting my experience here so I can remember all of them.

Firstly create your web service - The VS code out of the box will do. ie
New project->Visual C#->ASP.NET Web Service Application

This will give you code similar to the following:
namespace SimpleTestWebService
{
[WebService(Namespace = "http://iwaszko.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}


Run this code and envoke the http Post to test all is well.

Now choose File->Add new project->Other Project Types->Setup and Deployment->Web Setup Project

Now Right click on the WebSetup project and choose Add->Project Output














Make sure that the correct WebService project is selected and select Project Output, Debug Symbols & Content Files





Then Build the WebSetup project - (Depending on whether you Build in Debug or Release, it will put its setup.exe and websetup.msi in the same named directory)

Note: you can Install or uninstall the web service from VS by right clicking on the WebSetup project in solution explorer and choosing install/uninstall.





Once I installed the web service to IIS these are the issues I had:

1) Make sure you set your IIS site/virtual directory to use ASP.NET 2.0 if you are using VS2005 - see this post for examples

2) Accessing http://localhost/websetup/service1.asmx gave me the following very unhelpfull error:
Failed to access IIS metabase (see link)
This relates to an error where the local machine ASPNET cannot access the IIS metabase. It can occur where DotNet 2 has been installed after IIS and lots of other combinations.

Workaround: Microsoft published several fixes including using asp_regiis -ga ASPNET, however the best solution I found was to go to control panel-> add/remove programs and choose repair on the DotNet 2.0 install.

3) After the dotnet 2.0 repair succeeded, accessing the web service gave me a new error:


HttpParseException, Could not create type 'Service'. (see link)


The solution seems to be that when the package is deployed to the web server, the bin directory is created but the dll's are put in the directory above. Moving the dll to the bin directory manually seemed to fix this error, however I found a setting in the VS2005 deployment project which corrects this behaviour.


Select the Properties for Primary Output from the WebSetup project. Under the Folder property choose bin. This then seems to put the dll's into the bin directory and the web service works correctly.

Why such a simple thing such as deploying a web service seems to be so difficult is something I very much hope Microsoft is addressing with Orcas, however in the meantime I hope that these notes assist you in not having to struggle quite as much as I did.




No comments: