Adding WCF custom service behaviors in config

Lately I have been working with a bit of WCF for a client, and one of the things I have had to do is to create a service behavior to handle some security things. However, due to the fact that this application needed to run in several different environments, it needed to have different configuration under different circumstances.

The real need was actually to be able to remove the behavior in some circumstances, and add it in some. But I didn’t really want to do it through a bunch of if-statements in my behavior. Instead I wanted it to be done through configuration so that I could turn it on and off using config transforms…

More...

Have you seen Uri.GetComponents()?

If you haven’t, it is freaking brilliant! Well, at least very useful! And it has been around since .NET 2.0…

For some reason I keep ending up in situations where I need to get certain parts of a Url. In a lot of cases, I just want to extract the scheme and host name, eg https://chris.59north.com/, from a longer Url, and I don’t think I am alone. But if you Google it to find a good solution, you get a gazillion hits talking about how people have created this awesome method that takes the parts of the Url and uses string concatenation to build the result. Well, guess what…that sucks!

More...

Xml namespaces for custom control libraries

Ok, it has been a while since I posted now, but there has been a too much going on, and I guess I should be blogging about Silverlight 5, as it is on the agenda for MIX. I have even had the possibility to early access to the Silverlight 5 bits, but I have had too much to do to come up with some good posts about it. That is not to say that there isn’t a huge amount of really good stuff in the next release! But besides not having had time to play with it, I am not allowed to blog about it until it is actually available…

But, in the mean time, I thought I would do a quick post about a little feature that I am not seeing a lot of people using. It is nothing ground breaking, or even very necessary, but still helpful. I am talking about the ability to declare custom Xml namspaces to your assemblies…

More...

WCF, Silverlight and T4…a good combination…

Ok, so this post is definitely going down in the books as “why would you do that” for a lot of people, but it actually has its benefits in some cases. What I want to show, is how we can work with WCF services and service interfaces without having to add a service reference to Visual Studio and instead auto generate the required code using T4 templates…

So why would I want to do that? Well, in some cases it is kind of tedious and even complicated to spin up the service just to be able to update the service reference and in some cases it isn’t even possible to get access to the WSDL that is required to create it. And in those cases, this will help you… In my case, the services and service contracts are built by one dev, and the Silverlight stuff by me. To us, this way of working makes it a lot easier to handle changes to the service contracts as we go along… I can get changes by just checking out the changed interfaces without having to try and get my solution into a state where I can update my service reference.

More...

Using querystring parameters with the WebBrowserTask on WP7

I have just built a Windows Phone 7 app that is hopefully about to pop up on the marketplace within a couple of days. It is a fairly simple app, with very few impressive features. The most complicated part was to get the SQLite db used by the iPhone version of the app, to work on Windows Phone 7. Unfortunately I did not get SQLite to work on WP7. I ended up transferring the data to XML and adding some index tables, also in XML. But that isn’t the topic for this post.

The reason that I am writing this, is that I got stuck on a little thing while doing. Nothing complicated, but worth noting…

More...

Data binding images with MVVM

The title for this post make it sound like the world’s simplest thing. And to be honest, it sort of is. It is not hard to get images from the ViewModels into the view, but there are several ways of doing it. Each with its own pros and cons.

In my world, my VMs often get urls/uris to images instead of the actual image. The reason for this I guess is sort of the same thing as why you shouldn’t store your images in the database. The models can become huge if they include the images, especially if we add a couple different image sizes and so on. And that is without considering the possibility of us transferring a whole array of these objects across the wire. And in a lot of cases we don’t even show all the images in the UI, so why would we pass the images along if we don’t need them…

More...

MVVM and “restricted” functionality

So, I am back with a new post after WAY too long. It got really busy around TechEd Aus and NZ, and I really thought and hoped that I could get back and become active again as soon as that was over. Unfortunately, pushing work in front of you doesn’t really clear it…so when I finally got back from Auckland, I had a whole pile of things to do…

Anyhow…enough with the excuses…get to the topic already! So the topic is how to handle commanding with “restricted” functionality. There is two things in that sentence that I want to clarify. With commanding, I mean move functionality from the view into the viewmodel and removing as much code as possible from the code behind of the view. And with “restricted” functionality, I mean the type of functionality that cannot be handled anywhere but in the code behind of the view…

More...

Cool INotifyPropertyChanged implementation

While working on a little MVVM thingy the other day, I ran into a sweet little piece of code that I wanted to share. I have seen several version of this around the web, but this is where I found this particular version. The piece of code gets rid of the ugly part of the INotifyPropertyChanged interface. The part where you use strings to identify what property has changed. I understand that that is how you have to do it, but it feels messy. A common solution is to add constants to hold the strings, but that is not a very much better solution. it is still messy. So how can we handle it in a safe way? Well…one idea would be to do it like this…

More...

Live Writer plug-in for code snippets

I just remembered that I just HAVE to recommend this great plug-in for Windows Live Writer. It is the plug-in I use to add code snippets to my blog posts. There are a few things design wise I would probably want to be able to change. For example being able to turn off the scrollbars and show all the code formatted straight up in a nice way. But except those minor things, it is a great plug-in. You can find more info about it here and download it here.

If you know any REALLY good plug-ins for code blogging, don’t hesitate adding a comment about it. I’d love to find more goodies…I just don’t have time to go looking for them…