views:

167

answers:

2

Excuse the title, but it's best I just explain the problem.

I have 2 projects in my solution

  1. A Class Library
  2. A Web Application, which consists of a web service (asmx).

the web service has code sitting in the app_code folder, with a file [webservicename].cs

Inside the webservice code behind class, I have a web method here is a sample example (its simplified):

[WebMethod]
public EnumTaskExportState ProcessTask()
{
    var tm = new UploadTaskManager();
    return tm.ProcessTask();
}

Now at design time, in visual studio (2010 or 2008), when I right click on UploadTaskMananger, and then select "Go to definition". I get taken to AppData\Temp[some folder structure]...etc.... and it displays the public class definition.

Instead I would like to have complete integration, so that I get taken directly to the actual class in the class library project.

My guess is, this is happening because I am using the app_code route, and not a compiled file for the web service class. But I don't know any other way to do this.

How can I fix this? Possibly do away with the need for the app_code directory?

A: 

Its pretty easy

Step 1... when you generate a new web service , the app_code/.cs file gets generated too. Copy the signature from that class, it will be used as a template in step 4.

Step 2... delete the app_code/.cs file that got generated

Step 3. In your class file, create a namespace and folder structure where you will include the web service classes containing web methods. For example Class1.WebServices

Step 4. in Namespace Class1.WebServices (as per above example), create a new class, then replace the default class signature with the copied class signature from step 1.

Step 5. Edit the web service now, and create your web methods

Step 6. In the web application, edit the asmx file to reference the class without code behind for example

<%@ WebService Language="C#"  Class="Class1.WebServices.WebServiceClass" %>

Step 7, test!

JL
+1  A: 

You must be creating a web service by using File->New Web Site. I strongly recommend that you never build a web service in a web site.

Instead, create your web service by using File->New Project and selecting "WCF Service Application". If you're stuck using ASMX web services (which Microsoft now considers to be "legacy technology"), then select "ASP.NET Web Service Application".

These will both be Web Application Projects, and will behave like all other project types in Visual Studio.

Among other things, there will be no App_Code folder.

John Saunders
+1 to no app code. Have not really had the heart to look at WCF again, since the 3.5 version, because the general consensus is that its way too complicated (yes it sucks). When I feel brave again, I'll check out WCF 4. - Here is what MS say about WCF 3.x - direct from the horses mouth : The reality is WCF configuration usually becomes the most costly area of using WCF in practice today and much of that complexity lands on the IT/operations staff who are unprepared to deal with it.
JL
@JL: you must be confusing Entity Framework with WCF. There are no major changes in version 4 - you don't fix something so close to perfect. It is not complicated if you don't need the complication. Create yourself a "hello, world" service and look at the code. Don't bother to look at every configuration attribute - the default generated configuration includes default values that need not have been specified.
John Saunders
@JL: what is the source of that quote? I have not found that to be the case in real life.
John Saunders