Web API playing well with JQuery Templates

by DotNetNerd 1. May 2011 21:38

Since my last blogpost about Web API Glenn Block appeared on Hanselminutes so it seems to be hot stuff at the moment. Having already written part of this blogpost, as it was actually part of the last post before I decided to break it in half, it seems a good time to finish it and get it out there. So building on my last post I will also take a look at how Web API plays along with JQuery and the new JQuery templates.


Web API – for HTTP what MVC is for HTML

by dotnetnerd 25. April 2011 14:14

Over the last couple of weeks I have been looking a bit at the WCF Web API which I think is looking very promising. Web API is one of Microsofts newer open source projects,  aiming at providing http based services on top of WCF - while providing an easy to use API that give developers full control. In a way this makes me think of MVC, which has given control of the markup back to the developers, just like Web API is trying to do for http. Already loving what MVC has done for me, this makes me very positivt about the approach right off the bat.

RESTful services seem to be all the rage these days, which made me look at some of the choices we have as developers for doing REST. This was really my first look at Web API, so with it being one of the more exciting news at MIX11, it was only natural to take a deeper look.



I need a REST

by dotnetnerd 9. March 2011 18:37

One might think that the title of this blogpost is due to the fact that this summer I will be turning 30.
However it is actually a task I have been looking into, that could also be phrased as: I wish to build a REST based service, what are my options? With REST gaining in popularity I think this a question that a number of developers are asking themselves these days.

First of all what is REST? REST is about staying true to the HTTP protocol, and using it to communicate between a client and a server - as opposed to SOAP. To parafrase from Wikipedia being RESTful is about using URIs, HTTP verbs and mediatypes as the means to communicate using a traditional request/response model.



Tags: , ,

Ajax-enabled WCF services and loadbalancing

by DotNetNerd 10. June 2010 20:35

This week I ran into a problem when we were deploying a webapplication that uses ajax-enabled webservices to an environment that uses loadbalancing. The services were running fine in the stage environment and when each of the servers were called directly, but as soon as we went through the loadbalancer they failed.

I started by checking if the svc files could be reached, and surely enough they could be accessed from the servers, but through the loadbalanced domain I got a 404.

Reading blogposts on the subject provided little help – well actually it just hightened my degree of confusion. So after some time I started thinking about IIS bindings. I remembered that I had written a custom WebScriptServiceHostFactory because we had several bindings which IIS doesn’t handle too well.

using System;
using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Activation;

namespace MySite.ScriptingService
    public class MyCustomHostFactory : WebScriptServiceHostFactory
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            //This makes it possible to control which binding is used by sorting them in IIS.
            return new ServiceHost(serviceType, baseAddresses[int.Parse(ConfigurationManager.AppSettings["BindingIndex"] ?? "0")]);

I started playing around with which binding we used, and as I suspected if the binding was not the one for the loadbalanced domain it returned the 404. This was one of those “doh!” moments. I still had a problem though, because the site could be accessed both with and without the www subdomain. A colleague pointed to the fact that we could use the URL rewrite plugin for IIS, and have it ensure all traffic was directed through one of the domains. As it turnes out it actually has a CanonicalHostNameRule that does just this because its a SEO good practice. Only issue I had left was that umbraco on the other hand has a practice that it must be accessed directly on one server, so changes are made on the master and replicated to the slave(s). This just required extending the conditions so it does not redirect if the umbraco folder is part of the path.

IIS routing

So now by posting this I hope Ill save someone else from getting a few extra gray hairs, and if not maybe I’ll save my self some other time when I can’t remember how I did…

Tags: , ,

Opsætning af IIS 7.0 og Windows Communication Foundation i Vista

by DotNetNerd 16. December 2007 14:50

Jeg opdagede idag at det er knap så "lige ud af boksen" som man kunne ønske sig at afvikle ASP.NET og Windows Communication Foundation services under Vista og IIS 7. Man kan kun undre sig over at ihvertfald ASP.NET ikke automatisk installeres ved installation af IIS, men det er åbenbart ikke tilfælder. Det lykkedes dog efter at have rodet lidt at få det til at virke og jeg vil derfor lige skrive en guide hvis andre skulle støde på samme problem. 

Installation af IIS og ASP.NET på Windows Vista

For at kunne afvikle en ASP.NET applikation skal man først installere IIS og den tilhørende ASP.NET komponent. Dette kræver administrator rettigheder og gøres ellers ved at:

  • Gå til kontrolpanel -> Programmer og funktioner.
  • Herfra vælger du "Slå windows funktioner til eller fra" i sidemenuen til venstre i vinduet.
  • Vælg internet Information Service og udvid punktet.
  • Udvid "værktøjer til webmanagement" og "kompatibilitet med IIS 6 management".
  • Vælg "Kompatibilitet med IIS-metabase og IIS 6-konfiguration".
  • Udvid også "World wide web services" og Funktioner til programudvikling.
  • Vælg ASP.NET checkboksen.

Du kan nu afvikle ASP.NET applikationer ved at oprette dem på almindeligvis via IIS management værktøjet - eller bruge default sitet ved at smide det i inetpub/wwwroot.

Installation af WCF service modellen

For at kunne afvikle en Windows Communication Foundation service skal service modellen registreres.

Dette gøres ved at:

  • Åben en kommandoprompt med admin rettigheder.
  • Gå til %Windows%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\
  • Check status ved at skrive ServiceModelReg -vi og se om service modellen allerede er installeret.
  • Er den ikke installeret skriv ServiceModelReg -i og så skulle modellen blive installeret.

Og nu kan du så også afvikle en Windows Communication Service.

Lige for en god ordens skyld skal det siges at for at hoste en WCF service under IIS 7 skal man blot smide en svc fil med følgende indhold i roden af sitet.

<%@ ServiceHost Language="C#" Debug="true" Service="Syndication.FeedService" %>

Hvor servicen skal pege på klassen der implementerer din service. Dll'en skal ellers bare ligge i en bin mappe som den plejer.

Tags: , ,

Who am I?

My name is Christian Holm Diget, and I work as an independent consultant, in Denmark, where I write code, give advice on architecture and help with training. On the side I get to do a bit of speaking and help with miscellaneous community events.

Some of my primary focus areas are code quality, programming languages and using new technologies to provide value.

Microsoft Certified Professional Developer

Microsoft Most Valuable Professional

Month List

bedava tv izle