NOTE: instructions below are for MonoDevelop 2.6 Beta 2 - built on 2011-04-06 03:37:58+0000
Create a new ASP.NET Web Application in MonoDevelop:
- From the menu, select: File → New → Solution…
- Expand C#.
- Select ASP.NET → Web Application.
- Enter a name for the ASP.NET project that will be created in the solution in Name:.
- Change the root location for the solution in Location:, if desired.
- Change the name of the root solution in Solution Name:, if desired.
The Results – I
What you have after executing the new ASP.NET Web Application project wizard is a solution containing one ASP.NET Web Application project. In the default project view in MonoDevelop, you'll find the following items:
- Default.aspx – This is the default web form rendered and presented in the browser when http://<server>:<port>/ is accessed.
- Default.aspx.cs – This C# file contains the developer-created common code and event handlers which can be used to affect the processing of the form.
- Default.aspx.designer.cs – This C# file contains the IDE-generated code for the page.
- Global.asax – This file contains the basic information which is available to the entire application.
- Global.asax.cs – This C# file contains methods and event handlers for the entire application. These include event handlers for: application initialization, application termination, session handling, error handling, and request handling.
- web.config – This file contains the primary configuration for the application when deployed to a server. A secondary set of configuration options can be found in the server's Machine.config file.
If you go out to the location where you created the solution/project, you will also find a few other files:
- /<solution name>/<solution name>.sln – This file contains configuration information for the entire "workspace" of projects.
- /<solution name>/<solution name>.userprefs – This file is generated by MonoDevelop and contains information specific to the user of the MonoDevelop application. The consensus is that this file should not be included in source-control.
- /<solution name>/<project name>/<project name>.csproj – This file contains configuration information for the particular project.
- /<solution name>/<project name>/<project name>.pidb – This binary file contains meta-data generated by MonoDevelop. The consensus is also that this file should not be included in source-control.
Setting Up the Web Service
Since I'm only really interested in exposing a web service using this project, I felt that I really don't need the Default.aspx.* or Global.asax.* files as they are currently not doing anything for the project. I deleted all five of the files.
Create a new ASP.NET Web Service file in MonoDevelop:
- In the Solution pad, right-click your project and select: Add → New File…
- Select ASP.NET → Web Service.
- Enter a name for the file that will be created in the project in Name:.
The Results – II
After the ASP.NET web service wizard has completed, you'll find a new asmx file in your project. This file will contain the basic WebService directive, some using statements (System and System.Web.Services), a namespace, and a class definition.
Exposing a Method in the Web Service
Next, you'll want to create a method that you want to expose as a method on your web service. Add the WebMethod attribute to it. Your asmx file will now look something like this:
When you run this project, you can view a simple front-end for the service at http://localhost:8080/<web service file name>.asmx. This web form is created at runtime by the ASP.NET container.
What? No code-behind?
While it is normally a good practice to separate a view from the code which contains its logic, as in an aspx file, there is really no reason to do so in an asmx file as there is no visual component which must be separated from the code.