Skip to content

Pass JSON objects to MVC Controller

Pass javascript objects to MVC Controller with AJAX: One of these will fail bigtime: Which one do you think is correct?

data: "{ ‘client’: " + JSON.stringify(client) +", ‘list’: " + JSON.stringify(list) +" }"

data: {‘client’:JSON.stringify(client), ‘list’: JSON.stringify(list)}

Solution: Read this (

Rotate Text in ReportViewer RDLC

I’m working on other things for the moment, but I remember I was scratching my head half a year ago trying to put rotated text on a reportviewer localreport.

I was new to reportviewer and google was my mentor. We played along quite well until the issue with rotating text came up. Google gave me lots of tips, and most of the solutions was to write to Graphics object used to paint the page and rotate text manually (try searching ‘rotate text reportviewer’ yourself)

This worked fine, but then the rotated didn’t show up in the preview with the built in reportviewer control, because the “magic” with adding the vertical text happens when the reports is being written to the printer.

I spent a lot of time struggling with manually rotating with the Graphics object and the code wasn’t very friendly.

Today, a colleague of mine was working on a report and said to me. “Hey, Martin, remember when you struggled with the vertical text? Why didn’t you just use the WritingMode property on textbox?”

ARGH! I cannot believe I didn’t see that! To all of you: If you are going to write vertical text in reportviewer, there is a property on the TextBox “WritingMode” which can be set to “Vertical”. However, if you want to display text in other directions or angles, you have to use the first alternative with the Graphics object.


Den siste tiden har jeg hatt det morsomt av å lese Jonathan Skeets opprivende tilbakemeldinger av boken “Fluent C#” av Rebecca M Riordan. Og det er ikke fint lite han kritiserer denne boken. Fra hans twitterkanal @jonskeet har han pøst ut med opplysninger om boken som er direkte vranglære. I dette Google Docs dokumentet har han laget sin Errata for boken, og feilene fortsetter å ramle inn.

Jeg har ikke lest boken, men har lest noe av Jonathans Errata, og må si meg enig i at det er veldig mange unødvendige syntax feil i boken, samt flere alvorlige logiske feil. Rett og slett vranglære! Rebecca burde absolutt brukt mer tid på å kvalitetssikre boken sin før publisering, noe som har straffet seg merkbart!

Men på den annen side er dette den reneste uthengingen for Rebecca som har fått hele .NET eliten mot seg, og de sparer ikke på kruttet. I tillegg til å rette konkrete logiske feil, begynner de å korrigere kommafeil, og argumentere andre måter å løse problem på enn hvordan hun har løst det. Altså, ikke direkte feil, men andre innfallsvinkler og annen metodikk. Det synes jeg er feil, og de kunne holdt seg til å rette opp i hennes vranglære.

Men om jeg noen gang skal skrive en bok om .net og c# , så skal jeg sende en kopi til Jonathan FØR jeg publiserer Smilefjes

Se Jonathans Google+ innlegg og Errata her

Hosting a WCF Service in IIS with Net Tcp binding

I started experimenting with different bindings on a WCF service because an appilcation we hosted for a customer had some performance issues. This application transfered massive loads of data with a standard httpBinding, in others words, all your objects is serialized on the Service, transfered as text (XML), and then recreated on the client that consumes the service. With a net.tcp binding instead the data transfer will be a lot smaller because the transferred would be binary!

I tried a couple of tutorials on the internet but I struggled so I want to make my own here. Here is how make a simple service on localhost with a net.tcp binding:

I have Windows 7 Professional and IIS7 and for making a nettcp binding possible through you have to enable Non-HTTP Activation. (Sorry for the Norwegian language)


Then start a new WCF Service application project ‘WCFService1’ in Visual Studio and compile it. NOTHING ELSE! Just keep the original sample code.

Then we test it with the defautl httpBinding. Open IIS Manager and click on your “Default Web Site”. Then set the path for this website to your newly created WCFService1


Open up WcfTestClient.exe (in your Microsoft SDK folder) and add service http://localhost/Service1.svc
The service should appear like this

So far, so good. But what about that net.tcp binding?

Add another binding to your website through IIS Manager with net.tcp and binding info: “808:*”. This means that localhost will listen on port 808 which is default for net.tcp connections.


Go to Default Web Site –> Manage Website –> Advanced Settings and make sure that Activated protocols are “http, net.tcp”


Now you are almost done!
We have to modify our web.config for the WCFService application and change the bindings configured to nettcp instead of http. Make sure you have these lines

<endpoint address="" binding="netTcpBinding" contract="WcfService1.IService1">

and this one

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>

Voila! Try now to open up WcfTestClient.exe (in your Microsoft SDK folder) and add service net.tcp://localhost/Service1.svc

If you have some trouble with connecting, maybe you can temporary turn off your firewall. The firefwall can sometimes be blocking your port

New side project

Every true programmer should have side projects. I haven’t had this for a while, but now I want to do something about this. A colleague and I have this idea of a website which is pretty much self-driven and I can’t wait to jump on this one!

At work you don’t always choose your technologies and frameworks so I’ve been really anxious about starting up a new MVC 3 web application project with NHibernate (or EF) and a IOC container. Guys, I’ve NEVER created a project with an IOC framework, and that’s horrible. I am sure that start working with these technologies will enlighten me and give me deeper insight on constructing larger applications.

So this weekend we will start drawing sketches and creating requirements and setting up our first iteration. Godspeed!

MetroTwit goes buggy

My favorite twitter client is MetroTwit. It has all the features I need (not many), and it has minimalistic and nice UI.

But now, when trying to use two laptops, the client give me an error mesage. It’s nice and descriptive about something has happened to my authorization between the client and twitter. Then it asks me if I want to disconnect this authorization. I answer yes, but MetroTwit does nothing and gives the same error message. I answer no, and the application crashes. I have even tried reinstalling the whole client and deleting the data under /AppData in my user folder, but nothing changes.

I want my MetroTwit back!

TableAdapters and Query Configuration Wizard in Visual Studio

In my current project we are bound to use typed datasets for communicating between Business services  and the client application. Yes, I know every wiseguy out there hates datasets and prefer using an ORM like nhibernate and transfer POCO objects between client and server, but that is not an option here.

Except for vulnerability against tight coupling, typed datasets can spare you a lot of trouble and work. But there are some features, like the TableAdapter Configuration Wizard (TCW), which has its horrible flaws!

Ever tried to write your own custom SQL in the TCW? Well, for basic and simple queries it’s no problem, but try adding a simple CASE statement.
Now, the TCW throws an exception and the workarounds are few (please, let me know if anyone has any magic tricks)

There are many complex queries in this project and the result is that almost every TableAdapter has its own inherited class so we can manually set the Custom SQL there.

But the worst is when working with typed Datasets and TableAdapters with the ODP.Net Oracle Provder, the whole application becomes like a big zombie. If you are really lucky you can do some changes to a Dataset in a couple of minutes, but if you are very unlucky and working with a complex dataset, you can actually wait for an hour or two for letting vs2008-2010 apply your changes. Really. that’s not fast. Or effective.

I have been talking to Christian Shay, the product owner of  ODP.Net and he’s been promising us a fix for this mess very soon. Let’s hope he’s not a zombie, too.