freddes.se

…because I'm a nerd

Archive for the ‘ASP.NET’ tag

The importance of the order of routes in ASP.NET MVC

with 3 comments

mvc-logo-landing-pageLast week I had the pleasure of listening to a presentation from Scott Guthrie here in Stockholm, http://weblogs.asp.net/scottgu/archive/2009/12/06/my-presentations-in-europe-december-2009.aspx. One of the most interesting parts of the all day event was his talk about ASP.NET MVC 2. Yesterday I had some time off and started to try things out using Visual Studio 2010 Beta 2 and the ASP.NET MVC 2 template. It was running smoothly for a while until I bumped into a problem I recognized from earlier. I didn’t remember the solution right away, but soon I figured it out what was the key point in making the routes, registered in Global.asax, work properly.

The order when adding the routes using the MapRoute method on a RouteCollection object is important to avoid getting a 404 page when browsing to pages that are supposed to work. I will present the problem and the solution for it below.

Read the rest of this entry »

Written by Fredde

December 9th, 2009 at 1:49 pm

Hobby projects and books

without comments

I haven’t had time for any article writing lately, because of the simple fact that I have prioritized my hobby projects.

I have finally started using the ASP.NET MVC Framework, together with jQuery and a RESTful web service, using the WCF REST Starter kit. These frameworks and libraries are some really great stuff! Have a look at my project blog on http://develop.freddes.se/blog.

My good friend Gabriel Svennerberg, writing about useability on http://www.svennerberg.com, told me about a new book coming out soon, about the ASP.NET MVC Framework. There is a sample chapter available for downloading on http://www.asp.net/mvc. I haven’t read it yet, but will do so as soon as possible. Right now I’m reading another book, RESTful Web Services by by Leonard Richardson (Author), Sam Ruby (Author), David Heinemeier Hansson (Foreword), which is a great book so far.

Written by Fredde

March 17th, 2009 at 12:07 am

Using interfaces when implementing web services

with one comment

interfaceThe other day I wrote about sharing types between web services to simplify implementation of consumers of these services. You can read about it here. I mentioned a nicer way to accomplish almost the same thing and I will present it here, by giving an example.

The biggest difference is that you have to define an interface, let all web service producers implement this interface and you as a consumer will be left with a minimal amount of work to consume all these web services as long as their end points are well known.

Read the rest of this entry »

Written by Fredde

February 24th, 2009 at 11:46 pm

Multiple web service references sharing types

with one comment

play_btnIn this article I would like to point out a useful way to accomplish something that would be really easy, but still have been annoying me for the last couple of months. Imagine that you would like to get some data of some type from one web service and pass it on to another. The data types on both server sides are the same, but the compiler won’t let you pass the type from the first service on to the next one. Casting won’t work either, not without implementing some kind of home made casting method.

This is really really annoying, since the scenario stated above is really common in the web service world. I will present a solution to this, using the wsdl command line tool when adding web references instead of the built-in tool in Visual Studio.

Read the rest of this entry »

Written by Fredde

February 16th, 2009 at 11:14 pm

Service interfaces using XSD (cont’d MVC Web Service part 1)

with one comment

visualstudiologoThe other day I got a question from a colleague of mine, regarding the XML schema usage when defining a web service interface, like the one defined in series. The question was something like this: “How will the consumer of the web service react if the, from the XSD file, auto-generated class used as in and return parameters is updated?” I couldn’t give a straight answer, other than that I assumed it would be transparent to the consumer as long as no nodes were changed or removed and only new nodes were added to the schema. I decided to give it a try, using a really simple XSD and a couple of really simple web methods. I will give a schematic picture of the scenario that I will test out later on.

Read the rest of this entry »

Written by Fredde

December 29th, 2008 at 11:09 pm

Setup an ASP.NET Web Service Solution (MVC Web Service part 2)

without comments

In this article the actual MVC like design will start to show up. The previous article, , didn’t really have anthing to do with MVC, so let’s begin!

Almost all design patterns will make re-use of code easier, but to accomplish this it is important to setup the Visual Studio Solution in such a way to support this. In the setup I will show here I will make way for re-use and the implementation of the MVC design.

Read the rest of this entry »

Written by Fredde

November 25th, 2008 at 9:30 am

Defining service interface types (MVC Web Service part 1)

without comments

I decided to start the process of creating a web service using an MVC like design pattern by specifying the interface towards the consumers. The interface has to be “nice”, and by that I mean that the parameters and return values should be easy to understand and use.

I will show how to define an XML schema using a third party tool, Liquid XML Studio 2008. These schemas will be used when generating C# classes/types to be used as parameters and return values when defining the web service interface. A result of this is that the web service will look like it uses objects as parameters, but this is only a way to represent the XML documents that may be used as parameters.

Read the rest of this entry »

Written by Fredde

November 16th, 2008 at 6:40 pm

Introduction to an MVC like designed Web Service

without comments

The other day I tried to compose an article about how to design an ASP.NET Web Service using an MVC like design pattern. I ended up with a huge article and decided to rewrite it and split it into a couple of smaller articles. I will try to write these articles as independent of each other as possible.

The idea to this subject came up when attending a course, held by Gabriel Svennerberg (http://www.svennerberg.com), dealing with Javascript, JSON and Javascript libraries such as JQuery and DOMAssistant. I wanted to try out the Ajax support in JQuery consuming web methods exposed by a regular SOAP web service as well as a WCF service. The business logic for these two interfaces were to be the same and their methods should have the same set of parameters, in and out. Therefore I wanted to create a couple of controllers and models to be used from the exposed methods. The methods themselves are the views in this MVC like architecture.

Read the rest of this entry »

Written by Fredde

November 12th, 2008 at 12:42 pm

Windows event log and web applications

with one comment

When developing and running web applications, such as web sites or web services, it is nice and convenient to have some logging from the application. Instead of using a log file it would be nice to be able to use the built-in event log in Windows.

When running or debugging a web application from Visual Studio using the built-in web server, named WebDev.WebServer.EXE when looking in the task manager, it will cause no trouble logging to the event log but when publishing the site or service to a server environment, Windows 2003 Server and IIS, it will cause the application to crash. The IIS log file will show an error, status 500, indicating an internal server error. The application will crash due to insufficient permissions for the application to write to the event log.

Don’t worry! There are a couple of solutions to this and I will present one of them here, with the ability to be treated as a little tool for those who develop .NET web applications.

Read the rest of this entry »

Written by Fredde

September 6th, 2008 at 1:14 pm

Posted in .NET,Tips & tricks

Tagged with , ,

ASP.NET MVC Preview 5 Release

without comments

On the ASP.NET CodePlex web site I found that ASP.NET MVC Framework was released, preview 5, the other day.

As I have written in earlier posts about the MVC Framework I will try it out by using it in one of my hobby projects. So far I haven’t got the time to start this project but soon, really soon…

Read the rest of this entry »

Written by Fredde

September 2nd, 2008 at 5:47 pm