Tuesday, July 04, 2006

Transforming inline webservice code into codebehind

I somehow managed to add to one of my Visual Studio 2005 Web Projects a webservice that had the code written "inline" meaning the <%@ WebService Language="C#" Class="WService"%> tag, followed by the C# code. While Visual Studio has a decent Intellisense functionality in asmx files, ReSharper doesn't. So I felt the need to move the code into a codebehind file. You would think that adding the Codebehind="WService.amsx.cs" would be enough. No, it isn't! As the codebehind model for VS is to have the codebehind in a compiled dll, an error like "Cannot create type WService" will annoy the hell out of you. The solution is to add the cs file into the App_Code directory.
<%@ WebService Language="C#" Class="WService" Codebehind="~/App_Code/WService.asmx.cs"%>