Manually removing a windows service

I was working on a small project which involved building a .NET WorkFlow library and a windows service that invokes the WF library to perform a number of sequence activities.   After building the application I also had to build the installer so that I could install the service automatically on the production server.

The thing I missed was to put a custom action in the installer to remove the service.   So, when I uninstalled the application on the production server the service still existed.
Easiest way to remove a service is to open regedt32 and navigate to this path:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

Find the service you are looking for and delete it.

I did attempt to use the command from the command prompt “sc delete <service_name>” but this failed to remove it.

References:

http://stackoverflow.com/questions/197876/how-do-i-uninstall-a-windows-service-if-the-files-does-not-exist-anymore

Action(T) Generic Delegate

Very useful delegate to create anonymous functions…why? This is especially useful when you have repeated code within a function.

This particular example gets a list of tables from a database based on a key that is consumed by the id parameter.

The Action(T) delegate can have zero to several different parameter types.

Action getTables(String id) = delegate() {
List<Tables> lTables = new Select().From<Tables>.Where<Tables.RelatedId>().IsEqualTo(id).ExecuteTypedList<Tables>();
});

Call the function within the function you declared the anonymous function:

getTables(“1”);

That simple…Awesome!

References:

http://msdn.microsoft.com/en-us/library/018hxwa8.aspx

Using the HttpWebRequest class

In this particular scenario I had to initiate a request from another website in code and track its response to be modified and rendered back to the user.

I had a series of LinkButton html controls on the web form that consume one event.

<asp:LinkButton id=”link1” runat=”server” onClick=”genericEvent”></asp:LinkButton>

When the user clicks on a particular button, ASP.Net invoked the genericEvent event

Protected void genericEvent(object sender, EventArgs e)
{
LinkButton thisLink = (LinkButton)sender;
}

I have a Dictionary object that holds the ID of the LinkButton and a URL value

Dictionary<String,String> Dict = new Dictionary<String,String>();
Dict.Add(“ID”,http://www.google.co.nz);

I created a helper method that initates the HttpWebRequest class to return a response based on the Dictionary ID and URL chosen from the user using the LinkButton.ID property.

Private void GetResponse(String ID)
{
HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create(DicLinks[ID]);
WebResponse newResponse = newRequest.GetResponse();
newResponse.Close();
}

Protected void genericEvent(object sender, EventArgs e)
{
LinkButton thisLink = (LinkButton)sender;
GetResponse(thisLink.ID);
}

This proved very useful in the scenario of getting various types of information from different sources that can be manipulated and rendered into one view for the user.

References:

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

Using ASP.NET MVC on IIS6 or below

When you are building a web applicatio using the ASP.NET MVC framework on IIS7, it URL routing works smoothly and without any dramas.   But when it comes to IIS6 you have to make a comprimse especially if you are developing web apps within a shared hosting envoirnment.   I found the easist way is to change the URL routing table within the Global.asax file.

Origional file:

1
public class GlobalApplication : System.Web.HttpApplication
1
 {
1
 public static void RegisterRoutes(RouteCollection routes)           {                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");                routes.MapRoute(                     "Default",// Route name                     "{controller}/{action}/{id}",// URL with parameters                     new { controller = "Home", action = "Index", id = "" }                           // Parameter defaults                );
1
 }
1
 protected void Application_Start()
1
 {
1
 RegisterRoutes(RouteTable.Routes);
1
 }
1
 }

Change to the following:

1
public class GlobalApplication : System.Web.HttpApplication
1
 {
1
 public static void RegisterRoutes(RouteCollection routes)           {                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");                routes.MapRoute(                     "Default",// Route name                     "{controller}.aspx/{action}/{id}",// URL with parameters                     new { controller = "Home", action = "Index", id = "" }                           // Parameter defaults                );
1
 }
1
 protected void Application_Start()
1
 {
1
 RegisterRoutes(RouteTable.Routes);
1
 }
1
 }

Just add the .aspx extension so that it registers through the .NET Framework.

ALSO remember to do a Response.Redirect in the default.aspx page so that the first page will be your default URL routing page, otherwise you will receive a HttpException “The incoming request does not match any route.”.

Bring it on 2009!

I made a new years resolution to blog at least 3-4 times a week…well, as you see its now the 13th of Jan 2009 and this is my first blog for the year…i’m a little behind but not to worry.   Happy new year to you all..bring it on 2009!