Dennis van der Stelt

The most votes generally drown out the best votes

Community

News

  • Addicted to Refactor! Pro

Email Notifications

I read...

I Use...

Tags

Recent Posts

Archives

Worst day of my life

Today was most definitely the worst day of my life. I’ve decided to not use my weblog for personal matters, but this is an exception. Partly because I’ve talked on Twitter and MSN with a lot of folks about the pregnancy lately and partly because I need to spill my guts out on what happened. And maybe keep this for personal records so I can look up what happened in the future.

Last week, on Tuesday, my wife was taken to the hospital because of some stuff that doesn’t need to be mentioned here. It was because of high blood pressure. They kept her from Tuesday until Thursday and monitored her occasionally if everything was alright again. The send her home with an appointment for Monday morning to recheck if everything was alright.

This night, from Sunday to Monday, my wife felt a little pressure on her chest. We went to bed and a little later, around 12:00am she woke up because of the pain in her chest. She was really, really worried and told me I had to call the hospital. She had trouble breathing also. The hospital confirmed we should come.

So some time before 01:00am we arrived at the hospital and things started getting worse very rapidly. See hard major pain in the chest, constant pressure and had a hard time breathing. At some point the nurses were away, organizing stuff and I had the idea she fainted repeatedly. So I went to search for a nurse and a few minutes later four nurses gathered around my wife.

They then transported her to the delivery room because they have equipment there to monitor her and the baby. They gave her an intravenous for her high blood pressure. But the pain and breathing problems got worse and worse. They gave her an injection for the pain at around 02:00am for the pain, which seemed to really start kicking in around 02:30am. But instead of just removing the pain, it looked like she was seriously drugged. She spoke everything double (doublespeak) and didn’t respond very well to inquiries from either me nor the nurses.

At around 06:00am or so she had slept for almost the entire time. Occasionally she puked and spoke with doublespeak but almost immediately fell asleep afterwards. But at this time, the heartbeat of the baby started to faint. So the gynecologist was called and he arrived 15 minutes later or so. He felt the baby was asleep because of the drugs (the injection for the pain) and tried to wake it up. The heartbeat rose again, but he decided ten minutes later they’d do a Caesarean section after all.

They prepared her, moved her away to surgery and I had to put on some clothes so I could be with her. When I came in, no communication was possible with my wife at all. The baby was delivered and while I was with the baby, someone came in mentioning they noticed something and would put her to sleep. Also because she might choke in her own vomit if so would throw up again.

I went with the baby to the maternity ward where after a short time, the doctor came in mentioning my wife was put to sleep because she had a Intracranial hemorrhage.

I can tell you, my life came almost to a full stop at that moment.

I was later informed that she had two major intracranial hemorrhages and they needed to transfer her to Erasmus MC, a specialized hospital in Rotterdam. Multiple doctors went with the ambulance and the ambulance itself got police support to get there as quick as possible.

I’m now at home, ready to see my other three children who are at my brother-in-law. I went to Erasmus MC myself to check on my wife. She was in a three hour surgery where they removed a part of her skull and fixed one intracranial hemorrhage. The other was too deep into her brain to reach. The operation was successful, if you can call it that.

I’m going to the hospital tomorrow to check on my wife. She’s kept asleep right now with medication. They’ll stop the medication tomorrow and then we’ll have to wait and see if she’ll ever gain consciousness again. And if she does, in what state that will be.

Still in the first hospital is my new born daughter Marith, who might never know her mother. I’m seriously constantly praying if she will be alright, as He is the only one who can help her now.

WCF Simple Example in Visual Studio 2010 – part 2

This topic is covered in multiple posts

The previous post was the most simple example of creating a WCF service and calling it from a client application. In this post you can read how you can achieve the exact same behavior, but now manually adding every bit of configuration. So we’ll basically override the default endpoints, configure our won, resulting in exactly the same behavior.

The idea behind this is that you understand what WCF does and that you can do it yourself. Besides that, the previous .NET Framework versions don’t support the default endpoints, meaning that the solution at the end of this article also works in Visual Studio 2008.

What will we do?

  1. Add BasicHttpBinding endpoint
  2. Add MEX endpoint
  3. Add Metadata behavior

Metadata behavior
We’ll start with bullet three, simply because almost everything is already in place. The solution from the previous weblog post ended with this in the application configuration from the ConsoleHost application.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <serviceMetadata httpGetEnabled="True"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

The service behavior has no name, making it the default for all services in WCF4. All we have to do is give it a name. Change line 6 into the following.

                <behavior name="MyBehavior">

Adding BasicHttpBinding endpoint
We’ll now add the first endpoint using the BasicHttpBinding. Right under <system.serviceModel> we’ll add the <services /> tag and add our service. Completely empty this will result in the following.

<services>
    <service name="">
        <endpoint 
            address="" 
            binding="" 
            contract="" />
    </service>
</services>

Now we have to fill in the blanks. More information can be found in the articles about the WCF ABC and hosting the service.

  • Name
    This is a bit misleading, as you can’t just enter any name, it’s actually the type of the service.
    This must be the fully qualified name of the implementation of our service. This means not the interface, but the class. Its name is EmailValidator but its full name includes the namespace, resulting in EmailService.EmailValidator.
  • Address
    The address we don’t have to fill in, because the base address in our code already defines it. You can also define this in configuration as you can read in the post Address.
  • Binding
    The binding is simply basicHttpBinding. Note the camelCasing.
  • Contract
    Here we should enter the contract, which is our interface. As with the name attribute, we need to enter the fully qualified name, resulting in EmailService.IEmailValidator.

You can view the end result at the end of this article and in the download, also at the end of this article.

Adding MEX endpoint
The MEX endpoint needs the metadata behavior configured, but we’ll get back to that. First we need to add the endpoint. Again the WCF ABC, an address, binding and contract.

  • Address
    Because we cannot have this endpoint at the same address as the BasicHttpBinding endpoint, we need to enter “mex” here.
  • Binding
    This is simple, it’s just mexHttpBinding
  • Contract
    This is simple as well, although a bit weird, it HAS to be IMetadataExchange. Not the fully qualified name or anything, it has to be just this.

Enabling the metadata behavior
Now all we have to do is add the metadata behavior. This is done at the root of the service, where we first entered the name. There’s another attribute there called behaviorConfiguration. We have to enter the name of our behavior configuration there, which is MyBehavior.

End result
This results in the following configuration.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <services>
            <service name="EmailService.EmailValidator" behaviorConfiguration="MyBehavior">
                <endpoint 
                    address="" 
                    binding="basicHttpBinding" 
                    contract="EmailService.IEmailValidator" />
                <endpoint 
                    address="mex" 
                    binding="mexHttpBinding" 
                    contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MyBehavior">
                    <serviceMetadata httpGetEnabled="True"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

You can download the Visual Studio 2010 and the Visual Studio 2008 solution right here.

WCF Simple Example in Visual Studio 2010

This topic is covered in multiple posts

It’s been a long, long time since I wrote the original WCF Simple Example post. It was even before Visual Studio 2008 and since then, a lot of things changed. As still a lot of folks place comments and questions to that post, let’s have a look at what we currently have to do to get a service up and running and consume it in a client.

This time we’ll start with a class library assembly (a .dll) and we’ll host the service inside a console application. The client will use a Windows Forms application again. Although we do everything in Visual Studio 2010, most will be usable in VS2008. I will mention it when it isn’t and provide an alternative. I’ll be a bit more descriptive about what we have to do, so this post is a little longer than the original.

Create Project
First create a new class library where we will define the service itself. Choose New Project and select the Class Library as project template. At the bottom, name the project “EmailService” and the solution name “WCFSimpleExample2010”. If you can’t set the solution name, check the Create directory for solution box.

createnewproject 

Create the contract
We’ll first create the contract with only one method; or operation as they are called in WCF. Rename the file to IEmailValidator.cs and make it an interface with the same name.

Now add a single method signature called ValidateAddress that takes one string argument called emailAddress and returns a boolean. This is a normal interface, nothing fancy.

public interface IEmailValidator
{
    bool ValidateAddress(string emailAddress);
}

Now we need to tell WCF that this is our contract. We do that by adding attributes, but first we need to add a reference to System.ServiceModel. Right-click the project and select Add reference and select System.ServiceModel from the list. I’m using the Visual Studio 2010 Pro Power Tools so my screen might look different from yours, but the idea is the same.

AddReference in solution explorer AddReference2

Now you can add the attributes to your interface. On top of the interface place the ServiceContract attribute and on the operation place the OperationContract attribute. Add the using System.ServiceModel at the top of your codefile, or let Visual Studio do it for you by having your cursor in on of the attribute names. When you typed it in correctly and case sensitive, you can press CTRL + . and a context menu should appear to let you add the using automatically. Your interface should finally look like this:*

[ServiceContract]
public interface IEmailValidator
{
    [OperationContract]
    bool ValidateAddress(string emailAddress);
}

Create the service implementation
Now that we’ve created the contract we need to write code for the service to actually do what we want it to do. Create a new class and make it implement the interface. After that, use a regular expression to verify the email address and return true value if it’s correct. You should have something like the following code, or make up your own. :-)

public class EmailValidator : IEmailValidator
{
    public bool ValidateAddress(string emailAddress)
    {
        Console.WriteLine("Validating: {0}", emailAddress);
        
        string pattern = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$";
        return Regex.IsMatch(emailAddress, pattern);
    }
}

Now you have the two most important classes for your service. You don’t actually have to use an interface, but it’s a best practice. That way you can inherit multiple interfaces for or do versioning with different interfaces.

Creating the host
As said, for our host we’ll initially use a console application. Choose to add a new project and now have a Console Application as project template. Name it “ConsoleHost”.

CreateConsoleHost 

Add the reference to System.ServiceModel again and also to your EmailService project. In your Main method, create a ServiceHost object and give it the correct arguments in the constructor, as shown below.

Type serviceType = typeof(EmailValidator);
Uri serviceUri = new Uri("http://localhost:8080/");

ServiceHost host = new ServiceHost(serviceType, serviceUri);
host.Open();

On line 4 is the creation of the ServiceHost object. As first argument it receives the implementation of our service as a type. And a base address as second argument. Read more about base addresses here and more about hosting here. The type is defined on line 1 and the base address on line 2. Finally on line 5 our host is started.

WCF4 : Default endpoints
Now here’s a difference in .NET Framework 4.0 because this is not possible in previous version of .NET. Currently the default endpoints are used, which is a new feature to make configuration of your services less of a hassle. I like to explicitly define everything in detail so everyone knows what happens. But for our example, this works quite well. If you’re not using .NET 4.0 you might want to continue to part 2 of this weblog post, which will be posted later.

You could add the default endpoints yourself by adding host.AddDefaultEndpoints(); to the code, right before the host.Open(); statement.

How can we see what endpoints are configured by default? I have a little script from way back that displays everything currently running. I won’t go into details, just paste the following after the host.Open(); part.

#region Output dispatchers listening
foreach (Uri uri in host.BaseAddresses)
{
    Console.WriteLine("\t{0}", uri.ToString());
}

Console.WriteLine();
Console.WriteLine("Number of dispatchers listening : {0}", host.ChannelDispatchers.Count);
foreach (System.ServiceModel.Dispatcher.ChannelDispatcher dispatcher in host.ChannelDispatchers)
{
    Console.WriteLine("\t{0}, {1}", dispatcher.Listener.Uri.ToString(), dispatcher.BindingName);
}

Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate Host");
Console.ReadLine();
#endregion

Now you should be able to see the endpoints like in the first following screenshot. You can use a browser like Internet Explorer to go to the service uri and look at the default MEX endpoint.

ConsoleHostWithoutConfig mexendpointwithoutconfig

As you can see it’ll tell you that a MEX endpoint (aka metadata) isn’t configured yet. Now an easy way would be to do this via the new default endpoints. My first impression was that this would work.

Type serviceType = typeof(EmailValidator);
Uri serviceUri = new Uri("http://localhost:8080/");

ServiceHost host = new ServiceHost(serviceType, serviceUri);
host.AddDefaultEndpoints();
// This actually doesn't just simply work.
host.AddServiceEndpoint(new ServiceMetadataEndpoint());

On line 5 you can see that we add the default endpoints and line 7 adds the ServiceMetadataEndpoint, or the MEX endpoint. Unfortunately it cannot add the Metadata behavior itself, so you still have to do this yourself. The other way it to specify in configuration that you want metadata enabled. Also new in WCF4 is that you can inherit configuration. You can specify in either the machine.config or in your local configuration what should be enabled by default for WCF services. I recommend you don’t do this in machine.config, but that’s just my opinion. Here’s how I enabled it in my project configuration, the app.config of our console host. Remember that in the follow up post to this, we’ll do this the old fashioned way, which will work in Visual Studio 2008 and has my preference.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
                    <serviceMetadata httpGetEnabled="True"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

As you can see, I have not specified a name for the behavior so in WCF4 this means it’ll be used by all services. This also means that every service needs a base address for http endpoints.

For reference, here’s the code for our console host:

static void Main(string[] args)
{
    Type serviceType = typeof(EmailValidator);
    Uri serviceUri = new Uri("http://localhost:8080/");

    ServiceHost host = new ServiceHost(serviceType, serviceUri);        
    host.Open();

    #region Output dispatchers listening
    foreach (Uri uri in host.BaseAddresses)
    {
        Console.WriteLine("\t{0}", uri.ToString());
    }

    Console.WriteLine();
    Console.WriteLine("Number of dispatchers listening : {0}", host.ChannelDispatchers.Count);
    foreach (System.ServiceModel.Dispatcher.ChannelDispatcher dispatcher in host.ChannelDispatchers)
    {
        Console.WriteLine("\t{0}, {1}", dispatcher.Listener.Uri.ToString(), dispatcher.BindingName);
    }

    Console.WriteLine();
    Console.WriteLine("Press <ENTER> to terminate Host");
    Console.ReadLine();
    #endregion
}

Accessing the metadata
Because we now have enabled our service and our metadata endpoint, the MEX endpoint, we can view it through Internet Explorer or another browser. Execute the console host (it has to be alive or the endpoints won’t be accessible) and browse to the URI of your service : http://localhost:8080/

If this shows a nice screen with a link to the WSDL you’re very likely done with the service.

Create client application
We’ll now add another project that will consume the service and will be able to verify if entered email addresses are valid, or at least according to our regular expression.

Add a new console application like before and this time call it ConsoleClient. Make sure your service (the host) is running, but don’t have it running in debug mode. Easiest way is to set the ConsoleHost project as startup project en press CTRL + F5 to run it without debugging turned on.

We now need a proxy class that sits between our client and service. There are two ways to create a proxy for our service. I have a preference for doing it manually, so you know what exactly is happening. I’ll show that first.

Manually create proxy
First start up a Visual Studio 2010 (or Visual Studio 2008) Command Prompt and move to the location of the ConsoleClient. Because it’s a Visual Studio command prompt you should have access to the proxy generator svcutil.exe. Input the following commandline

svcutil http://localhost:8080/ /o:ServiceProxy.cs /config:App.Config /n:*,ConsoleClient

This should generated two files, the service proxy and an application configuration file. Go back to Visual Studio and in your ConsoleClient application make all files visible through the icon at the top of the Solution Explorer, as seen in the right screenshot. The App.Config and ServiceProxy.cs should become available and you can include these.
Update : The console window screenshot shows ConsoleHost as namespace, this is incorrect and should be ConsoleClient as the full commandline statement above states.

CreateProxy1 CreateProxy2

 

When we ran svcutil.exe the first argument was the location of our service as specified in the host. This is the base address. The second argument is what the tool should output, our proxy. The third argument is that we also want it to update our application configuration and if it’s not available, create it. The last argument is the namespace our proxy should be placed in (or should have), which should now be the same as our application itself.

Call the service
Now we can finally start consuming the service. When you go to your Main method in your Program class again, you can access the proxy class, which is the name of your service with Client suffixed. So ours is EmailValidatorClient.

EmailValidatorClient svc = new EmailValidatorClient();
bool result = svc.ValidateAddress("dennis@bloggingabout.net");

In line 1 you can see the proxy being initialized. Does doesn’t mean the connection is set up, this is done on first call. Line 2 shows the calling of the service and getting the result back.

This is our entire method Main which will continue to ask for email addresses until you enter none.

static void Main(string[] args)
{
    while (true)
    {
        Console.WriteLine("Enter an email address or press [ENTER] to quit...");
        string emailAddress = Console.ReadLine();

        if (string.IsNullOrEmpty(emailAddress))
            return;

        EmailValidatorClient svc = new EmailValidatorClient();
        bool result = svc.ValidateAddress(emailAddress);

        Console.WriteLine("Email address is valid : {0}", result);
    }
}

Creating proxy through Visual Studio, the easy way.
Instead of creating the service proxy manually, via svcutil.exe, you can also let Visual Studio create it for you. Just right-click the project and select ‘Add Service Reference...’ You’ll get a dialog window where you enter the address of your service and the namespace.

CreateServiceReference

Now we entered ConsoleClient as namespace, but it concatenates this to the already existing namespace. So now you can access the EmailValidatorClient via ConsoleClient.ConsoleClient.EmailValidatorClient. One of the reasons I don’t like to use this automatically generated proxy class. You should now not forget to add a using statement to this namespace at the top of your class. Probably a better solution is to set the namespace to Proxies or something, in the dialog, so the complete namespace makes more sense.

Run the client
While the service is still running (of not, restart it) you can right-click your ConsoleClient and select Debug and Start new instance and you’re done.

What next?
Next we’ll extend this blogpost with at least two more, step-by-step blogposts explaining how to manually add endpoints and how to host your service in IIS. You can read more about it here.

Download
Here's the download for VIsual Studio 2010. In the follow up article a Visual Studio 2008 solution is available.

Workflow Tracking Profile Editor

For those using Windows Workflow Foundation 4 (WF4) this might be a very interesting tool. I was messing a bit with creating a Tracking Profile for my WF4 workflows, but wasn’t succeeding very much. Until the Workflow Tracking Profile Editor was mentioned on the AppFabric forums.

This tool makes it dead easy to create a tracking profile. It allows you to load up a WF4 XAMLX file. It then shows the editor and you’re allowed to browse through all (composite) activities. After right-clicking an activity (with a blue circle on it) you can specify what you exactly want to track. It even knows everything about arguments and (scoped) variables so you can use checkboxes to turn them on or off.

 wf4tracking  wf4tracking2 

This way you can track what arguments go in, come out, what the value of variables was before and after you executed the activity. Very handy and probably a lot of work if you had to enter all the details by hand.

Download the tool here.

Microsoft AppFabric explained for SDN

Last Tuesday, may 18th 2010, I gave a presentation on Microsoft’s AppFabric. I explained that there are actually two themes of it; Windows Server AppFabric and Windows Azure AppFabric. They both have their own products.

  • Windows Server AppFabric
    • Services and Workflow Management
      This is sometimes called “Hosting” and was known under its codename “Dublin”
    • Caching
      Distributed caching which was known under its codename “Velocity”
  • Windows Azure AppFabric
    This was known under its previous name as “.NET Services”
    • ServiceBus
      This is used to connect applications through firewalls, proxies and NAT.
    • Access Control
      Once you’ve connected your applications, you might want to secure the connection.
      This is also used to map different identity stores so you don’t need federated identities.

You can download the slidedeck and the demos.

A short review on all 4 products

  1. Services and Workflow Manangement
    This seems quite cool and quite stable. Surely something you’d want to use asap if you’re running WCF services and/or WF workflows.
  2. Caching
    This one is quite hard to grasp at first, especially the terminology used. It’s also a shame there are no decent tools to work with and monitor stuff. Try to introduce this within your IT department as they need to provide one or more machines as a caching server. I’m going to try though!
  3. ServiceBus
    Not very difficult to grasp and use, but you sure need to find a good project to be able to introduce this.
  4. Access Control
    One of the hardest parts of the AppFabric, but isn’t security always a ***? But Access Controls probably tops those all as there aren’t any good examples for mapping identities and no tools whatsoever to support it.

Let me know if you have any experience with these or if you’re planning on using it!

MIX 2010 Keynote coverage

Remark : For some reason it doesn’t want to upload images anymore, I’ll have a look at it later!

This post will be used right now to give live coverage of the MIX10 keynote. My wife bring my meal when keynote is half way through and I have a beer at hand and watching some young dude doing magic with a yoyo! :-) I’m good to go!

17:10 Cool is that you can even get subtitles for if you’re hearing impared! Press the “cc” button to see it!

17:11 Scott Guthrie is coming up! No “TheGu” intro-video this time! :)

17:17 You can get the Olympics media framework with code at http://smf.codeplex.com/. Silverlight will support Fullscreen viewing on a single screen while working on another one. Sweet!

17:21 Blend 4 will be out this week and you get a free upgrade if you have version 3.

17:23 eBay will use Silverlight to be able to install their tool easily onto the desktop with Silverlight’s OOB ability. You can sell items through this tool and add information using your webcam to scan the barcode! It has also has the ability to drag & drop pictures onto the application. Silverlight really seems the way to go for a lot of your applications! They’re also showing a great sketchflow example of the application in the last image!

17:34 Silverlight 4 RC is available for download now! Get started here with the Pivot control.

18:00 Scott Guthrie is showing Visual Studio 2010 development for Windows Phone 7 with Silverlight. So far the designing and development and deployment to the WP7 emulator is extremely fast, especially compared to .NET Compact Framework development.

First image shows the initial Windows Phone project with the VS2010 Silverlight designer. Second image shows Scott Guthrie editing his form, whereas he’s running it inside a Windows Phone emulator, debugging from Visual Studio 2010. The last shows his final application, retrieving his last tweets from Twitter, using a web request and filtering it with LINQ to XML.

18:24 On the MIX10 site you can get minor details about free tools for Windows Phone developers!

  1. Visual Studio 2010 Express for Windows Phone
  2. Windows Phone 7 Series add-in to use with Visual Studio 2010 RC1
  3. XNA Game Studio 4.0
  4. Windows Phone 7 Series Emulator for application testing
  5. Expression Blend for Windows Phone CTP (free only for CTP most likely! :)

 

18:25 Netflix application build in Silverlight for Winodws Phone 7 is shown. Smooth videos instantly over 3G!

18:30 Great DeepZoom demo using Marvel comics, flicking through pages and zooming into the pages and specific images.

18:33 Laura Foy is showing FourSquare on Windows Phone 7

18:38 This is almost an iPhone… I guess! :) Shazaam on Windows Phone 7 by Jeff Sandquist!

18:39 Charlie Kindel on stage, thé Windows Phone guy! And he’s a soccer fan?! #fail :)

18:42 Loic Le Meur from Seesmic is showing the Silverlight client on both the desktop and Windows Phone.

18:46 Code4Fun is showing network communication with a Tank shooting red shirts into the audience

18:52 Larry Hryb aka Major Nelson showing of XNA on Windows Phone 7. Images below are from debug mode in VS2010!

Okay, so the first Mix 2010 keynote is over and they did not reveal much NEW information. It’s nice to see Windows Phone Silverlight finally arrive, as I was at MIX07 and saw the first light of Silverlight for Windows Mobile that was never released. Hope we can get our hands on all the Phone bits really soon and start developing for it. And more importantly, have it on our own Windows Phone hardware!

AppFabric : Configuration binding extension could not be found.

I have recently installed the Windows Azure AppFabric SDK because I’m writing an article for the Dutch .NET Magazine. Problem is I try to do everything in Visual Studio 2010 these days, just because it’s so cool to have something that’s buggy. Seriously! Sometimes you get headaches because you just can’t figure out why something’s not working, only to find out it’s because it really isn’t working because of the current beta version you’re working with. But on the other side it’s really fun and you learn a lot.

As now, when I got the following message.

Configuration binding extension 'system.serviceModel/bindings/netTcpRelayBinding' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.

It’s a System.ConfigurationErrorsException which can mean that you might be right with what you configured, the .NET runtime just can’t figure out what it is that is wrong. This time it’s because some extensions to WCF weren’t added to the machine.config of .NET 4.0 RC. It was however added to the machine.config of .NET 2.0 so I took it from there. And for future reference for my dear readers and all others that come in via Google, I’m posting the fix here.

Sidenote : I’m using 2.0.50727 and 4.0.30128 version of the .NET Framework, but the versions might differ on your machine.

Go to C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\ and read the machine.config from there. In the node configuration\system.servicemodel\extensions\ you find two nodes. The first is bindingElementExtensions and the second is bindingExtensions. You’ll see some bindings with a name that contains “relay” in it. Copy these into notepad or so.

Now open up C:\Windows\Microsoft.NET\Framework\v4.0.30128\Config\ and edit the machine.config there. Copy the lines from the 2.0 config that are missing in the 4.0 config and your AppFabric service should be able to start.

ClickOnce manual updates

I’ve written some tutorials in the past to help people with manually updating their ClickOnce deployed applications.

  1. Manual check for updates with ClickOnce
  2. Turn off automatic updates with ClickOnce
  3. ClickOnce automated build and pfx file
  4. Creating ClickOnce deployment files using an automated build and FinalBuilder

clickonce_autoupdate_3[1]

Miscellaneous users still had problems with the updates not checking very well. Joe responded with a solution. I’m writing it down here so more people might benefit from it as well, especially since the comment didn’t contain any linebreaks! :)

As Joe mentions the methods CheckForUpdate() and CheckForDetailedUpdate() persist the information retrieved to disk. This way when performing the check for update again, the information is retrieved from disk. If you’ve chosen to skip the update, it won’t ask you again.

You can override this behavior by using an overloaded method of the above mentioned methods and specify that you don’t want the information to be persisted to disk.

ApplicationDeployment updateCheck = ApplicationDeployment.CurrentDeployment;
UpdateCheckInfo info = updateCheck.CheckForDetailedUpdate(false);

//
if (info.UpdateAvailable)
{
    updateCheck.Update();
    MessageBox.Show("The application has been upgraded, and will now restart.");
    Application.Restart();
}
Check the second line with the method CheckForDetailedUpdate where I pass a ‘false’ to specify that it should not persist the update information.
Season greetings from BloggingAbout.NET

basmallBloggers, visitors and spammer, we have a season greeting for you if you click the link.

Hope everything goes well for you in the new year! 

Season greetings…

Scott Hanselman happy to be inside a Vertigo Player

scotthanselmaninsidevertigoplayer

New era

Tellus logo Since November 1st I’ve switched jobs and am no longer working at Class-A. I’ve had a really good time there and was unaware of the growth someone (like me) could make when you start a career as trainer and coach. Some of my colleagues were the best to work with, both professionally and personally. Thanks to everyone there.

However it’s time to move on for me for various reasons. I’m began a new career at Tellus, a company of about 60 employees. It’s doing some really great and advanced stuff on both .NET development and infrastructure and also has a huge vision and plans for the future of which I hope to be a part of.

I will most definitely not disappear from the .NET community and hope to do a lot more blogging and make an appearance at conferences like before. I’ve already got some plans on how to share some hands on experience with other people, lessons learned from the past. I’d really like to share some insights there, share knowledge and hopefully get some back as well. I’m really excited and will keep you updated.

Zune player in taskbar

 zunetaskbar This is pretty sweet, you can have the Zune player in your taskbar.

On previous version of Windows, I had my media player up there. But now the Zune player has this ability in Windows 7 as well.

If you have the Zune 4.0 software installed you can right-click the Windows 7 taskbar, select toolbars and then select the Zune toolbar. Now whenever you minimize the Zune player software, the icon will disappear and the player will be in the taskbar. The larger image on the left appears when you hover over the minimized player.

On the Windows weblog there’s more information available about the combination of Windows 7 and the Zune software. There are other options available that might interest you.

Zune software updates for Zune 4.0 optimized for Windows 7

Create a custom caching manager for Enterprise Library 4

I wanted to create a custom caching manager for Enterprise Library 4 that did… nothing. I Googled and Binged but could not find a way to temporarily turn off caching completely. And I want that so I can do some performance tests with the websites we have on the server. I don’t want to know how fast my app is, I want to load test the server and see how it performance, with and without caching. So that’s why I decided to create a Caching Manager that did nothing.

The documentation did not tell me much though, and there are some really weird gotchas in there. Here’s the part about the custom caching manager.

caching_documentation

Inherit from ICacheManager and add ‘the following configuration element’. And they’re serious about that part!!! I’ll show you why. Here’s what I did. First, I created a new Class Library and added a class named PointlessCacheManager that inherits from ICacheManager and put the attribute on top of it. I added another one for those who need it, but it’s commented out. This extra class also does absolutely nothing! :) First the custom cache manager.

//[ConfigurationElementType(typeof(PointlessCacheManagerData))]
[ConfigurationElementType(typeof(CustomCacheManagerData))]
public class PointlessCacheManager : ICacheManager
{

    public PointlessCacheManager()
    {
    }

    public PointlessCacheManager(NameValueCollection collection)
    {
    }


    public void Add(string key, object value, CacheItemPriority scavengingPriority, ICacheItemRefreshAction refreshAction, params ICacheItemExpiration[] expirations)
    {
    }

    public void Add(string key, object value)
    {
    }

    public bool Contains(string key)
    {
        return false;
    }

    public int Count
    {
        get { return 0; }
    }

    public void Flush()
    {

    }

    public object GetData(string key)
    {
        return null;
    }

    public void Remove(string key)
    {
        return;
    }

    public object this[string key]
    {
        get { return null; }
    }
}

If you use the CustomCacheManagerData you need the constructor with the NameValueCollection as parameter. The PointlessCacheManagerData uses the default constructor, or you can modify it to whatever you like.

Are we done yet? Maybe almost!!!
Again, if you want to have a custom cache manager that does nothing, you’re done with adding classes and you can skip the next part and continue reading at the configuration part. If you need more, like your own configuration, read on…

Now here’s the second class, with an even lesser implementation.

[Assembler(typeof(PointlessCacheManagerAssembler))]
public class PointlessCacheManagerData : CustomCacheManagerData
{
}

But this PointlessCacheManagerData class also references another class named PointlessCacheManagerAssembler. These two classes are used for reading configuration and initiating the cache manager. Here’s the last class.

public class PointlessCacheManagerAssembler : IAssembler<ICacheManager, CacheManagerDataBase>
{
    public ICacheManager Assemble(Microsoft.Practices.ObjectBuilder2.IBuilderContext context, CacheManagerDataBase objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
    {
        PointlessCacheManager createdObject = new PointlessCacheManager();
        return createdObject;
    }
}

Configuration
app_config_entlib Now comes the fun part. You want to configure the new cache manager in your application. Most of it is pretty easy though. Open the Enterprise Library Configuration application, or open up the application configuration by right-clicking it in Visual Studio, as you can see on the right.

When the configuration is opened (either in the seperate EntLib Config app or in Visual Studio), right-click the configuration node and select “New” and “Caching Application Block”. A new node should be added and under it you should see a node called “Cache Managers” with the default cache manager under it. Right-click the “Cache Managers” node (or folder, if you will) and select “New” and “Custom Cache Manager”. This is where you’ll configure your PointlessCacheManager.

However, and this is a big however. Two even. But only if you used another class than the default CustomCacheManagerData in the attribute on top of your PointlessCacheManager. Because the documentation told you to put “[ConfigurationElementType(typeof(CustomCacheManagerData))]” on top of your custom cache manager. And as I said before, they mean what they say. Although we don’t want to use that class when we implement our own configuration, we need to put the CustomCacheManagerData on top anyway. If you did that and compiled the class, we can configure our custom cache manager.

app_config_entlib_2 You can first give this one a name. I named mine “Pointless Cache Manager”. Note the spaces, the name is nowhere related to class names. Now select the “Type” key so that you can add a value. A small button should come available to select the type in an assembly. I pointed it out in the image on the left. Locate the assembly with the PointlessCacheManager in it on your harddrive. You should get the following image. If not, read on as well.

app_config_assembly

REMEMBER : When you made a change, mistake or anything like this, you need to restart the host of the configuration, to be able to see the changes. In other words, when you loaded the Enterprise Library Configuration application, restart it. When you’re changing the configuration in Visual Studio, restart it. Because it loads the assembly and never refreshes it, so changes aren’t visible until you restart the host application.

Make sure you’ve got the commented out line in the PointlessCacheManager uncommented so that it exactly (!) states what the documentation states. Once you’ve configured it correctly in your application’s configuration (or web.config) you can change it back to where it states that you’re using the PointlessCacheManagerData instead of the CustomCacheManagerData, recompile and work with it.

Now you can switch back and forth between the normal en the pointless cache manager.

SDC 2009 slidedecks and demos

DSC_0130 For me this was my first SDC and I really had a lot of fun. Great discussions with speakers and attendees. And as Dennis Doomen mentioned, the evening was pretty fun as well. I did two sessions, on about Test Driven Development, a basic introduction with some best practices. And also a presentation on Microsoft’s solution to distributed caching, “Velocity”.

Introduction into the TDD Mantra (slides and demo)
So you've heard about Test Driven Development but you're not sure what it is? Not sure if it is what you're doing? And if's "Test Driven", why do people say tests are less important? Why do tests first have to fail? In this session you'll learn what Test Driven Development is really about. About the simplest thing first and growing your application larger and larger. Until TDD made your application into what it should be, instead of what you thought it was going to be.

Distributed caching with Velocity (slides and demos)
It's been some time since Velocity was introduced, and it hasn't gotten the attention it deserved. Velocity is a distributed caching framework which means it can cache your application's data and distribute this over multiple machines for performance, backup, etc. If you want to know how to use Velocity in your project and/or your website, come join me for this session.

If you have any questions about any of these subjects, don’t hesitate to contact me.

Syntaxhighlighter

I’ve tried a lot of tools and addons to use syntax highlighting on my weblog and BloggingAbout.NET in general. I’ve fallen in love with two of them.

The first I use to use for my weblog. But this causes a lot of markup within the code and it can never be changed later on. I still use CopySourceAsHtml for posting in PowerPoint, Word and other tools though. Simply because it’s really, really good and easy to use from within Visual Studio.

SyntaxHighlighter is a set of Javascript that gives your code its color after it’s being displayed, ie. when the page has loaded. The code itself is rendered within <pre> tags and has no specific markup in HTML for the coloring. This makes the highlighting a bit slower, but with the additional benefits that there’s no extensive markup in the code, that the coloring libraries can be updated. Additionally a popup window is displayed for easily copying the code and some other useful buttons.

For installation I’ll redirect you to the official site.

SyntaxHighlighter plugin for Windows Live Writer : PreCode
What makes my life especially easy as a blogger, is this plugin called "PreCode". The plugin fits nicely into Windows Live Writer and with a popup window, a paste and a fix indentation you have some new code layed out on your weblog. Could not be any easier.

This is the end result:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Hello world");
            }
        }
    }
}
More Posts Next page »