blogs.conchango.com

welcome to the conchango blogging site
Welcome to blogs.conchango.com Sign in | Join | Help
in Search

Paulo Reichert's Blog

  • Visual Studio Update for Windows Vista

    It seems that Microsoft has quietly released the final version of the Visual Studio 2005 SP1 Update for Windows Vista pack. It supposedly adds full compatibility for Visual Studio 2005 running under Windows Vista, althouh you still need to run it as admin. It was available in beta form since the SP1 for VS 2005 was released and Microsoft had announced before that the release version would be made available in Q1 '07, so here we go.

    Note that if you have installed the beta version of this update you will need to uninstall it before applying the release version, as usual.

  • WCF Reliable Sessions Puzzle

    As I mentioned on my previous post, I have spent a few days very puzzled with a behaviour in WCF reliable messaging/sessions.

    THe problem all starts because as documented here, creating WCF clients (the classes generated by svcutil.exe) is quite expensive due to the rich set of functionality implemented in WCF. You can learn more about the client model here. To overcome the problem, there are basically two options:

    1. Create a ChannelFactory instance and keep that in the application context somewhere, so you don't have to initialize the factory every time you need a client. You then use this factory to create client channels directly;
    2. Create a client instance and cache that to be reused for multiple calls.

    Ultimatelly, option 2 offers the best performance, as you go through the expense of instantiating the client only once. I then wrote a pool class to manage a number of client instances and all was nice and cool until the clients' connections started to be closed by the WCF host due to inactivity (I'm using NetTcp binding). As my application is the only one to use my WCF service and I can control the number of client connections open to the host at one time, I wanted just to keep these connections alive for as long as the client application lived, so I thought about using Reliable Sessions for that. Basically, as documented here, reliable sessions are kept alive by the WCF architecture indefinitely, so that's good for what I need.

    The weird thing started when after enabling reliable sessions in my app, the behaviour of the host didn't change: it would still drop my connections after 10 minutes and everything would go bad. I then wrote some simple code to try to replicate the problem, code that can be seen below:

    using System;

    using System.ServiceModel;

     

    namespace Service

    {

        [ServiceContract(SessionMode = SessionMode.Allowed,

           Namespace = "http://tempuri.org/Services/IServiceContract")]

        public interface IServiceContract

        {

            [OperationContract]

            string DoSomething(string arg);

        }

     

        [ServiceBehavior(Namespace = "http://tempuri.org/Services/ServiceImplementation")]

        public class ServiceImplementation : IServiceContract

        {

            #region IServiceContract Members

            public string DoSomething(string arg)

            {

                return string.Format("The string passed in was '{0}'.", arg);

            }

            #endregion

        }

     

        class Program

        {

            static void Main(string[] args)

            {

                using (ServiceHost serviceHost = new ServiceHost(typeof(ServiceImplementation)))

                {

                    serviceHost.Open();

                    Console.WriteLine("Service running. Press any key to exit.");

                    Console.Read();

                    serviceHost.Close();

                }

            }

        }

    }

     

    The configuration file for the service looks like the following:

     

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

        <system.serviceModel>

            <bindings>

                <netTcpBinding>

                    <binding name="NetTcp_Reliable">

                        <reliableSession ordered="false" inactivityTimeout="00:10:00"

                            enabled="true" />

                    </binding>

                </netTcpBinding>

            </bindings>

            <behaviors>

                <serviceBehaviors>

                    <behavior name="MetadataBehavior">

                        <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:2526/Service" />

                    </behavior>

                </serviceBehaviors>

            </behaviors>

            <services>

                <service behaviorConfiguration="MetadataBehavior" name="Service.ServiceImplementation">

                    <endpoint address="net.tcp://localhost:2525/Service" binding="netTcpBinding"

                        bindingConfiguration="NetTcp_Reliable" contract="Service.IServiceContract" />

                </service>

            </services>

        </system.serviceModel>

    </configuration>

     

    For the client application I have used svcutil.exe to generate the WCF client and the configuration file. The client is pretty ordinary and I haven’t changed anything so I will spare you the bore of reading it, but the config file looked like this:

     

    <?xml version="1.0" encoding="utf-8"?>

    <configuration>

      <system.serviceModel>

        <bindings>

          <netTcpBinding>

            <binding name="NetTcpBinding_IServiceContract" closeTimeout="00:01:00"

                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

                transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"

                hostNameComparisonMode="StrongWildcard" listenBacklog="10"

                maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"

                maxReceivedMessageSize="65536">

              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

                  maxBytesPerRead="4096" maxNameTableCharCount="16384" />

              <reliableSession ordered="false" inactivityTimeout="00:10:00"

                  enabled="true" />

              <security mode="Transport">

                <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />

                <message clientCredentialType="Windows" />

              </security>

            </binding>

          </netTcpBinding>

        </bindings>

        <client>

          <endpoint address="net.tcp://localhost:2525/Service" binding="netTcpBinding"

              bindingConfiguration="NetTcpBinding_IServiceContract" contract="IServiceContract"

              name="NetTcpBinding_IServiceContract">

          </endpoint>

        </client>

      </system.serviceModel>

    </configuration>

     

    These settings are pretty much the defaults for NetTcp binding except for the reliableSession element that enables RM and disables message ordering. The console application that uses the WCF client looks like the following:

     

    namespace Client

    {

        class Program

        {

            static void Main(string[] args)

            {

                ServiceContractClient client = new ServiceContractClient();

                client.InnerChannel.Faulted += new EventHandler(InnerChannel_Faulted);

                Console.WriteLine("The call was made at {0} and the response was '{1}'", DateTime.Now, client.DoSomething("First Call"));

                Console.WriteLine("Press any key to call the server again!");

                Console.Read();

                Console.WriteLine("The call was made at {0} and the response was '{1}'", DateTime.Now, client.DoSomething("Second Call"));

                Console.Read();

            }

     

            static void InnerChannel_Faulted(object sender, EventArgs e)

            {

                Console.WriteLine("The channel faulted!");

            }

        }

    }

     

    The above console application allowed me to let the application hit the service once, then I could leave it idle for as much as I wanted and try to hit the service again after pressing any key. It will also handle the Faulted event in the client’s inner channel. The behaviour I was expecting is that regardless of how long I left the application idle after the first call to the service, when I pressed a key I would still be able to call the service again. What happenned instead is that after 10 minutes of the application iddle, the Faulted event of the channel would be raised, telling me that the connection was gone.

     

    My first thought was to increase the InactivityTimeout on the reliable session configuration in both client and server to 20 minutes instead of 10 and see what happened. When running the application it would still fault the channel after 10 minutes.

     

    After posting in the WCF forums I was pointed to the Receive Timeout in the binding configuration. After reading the extensive (NOT) documentation available for this property I was led to believe that it was the time alowed for a receive operation (i.e. the time the client takes to send a full message stream) to be completed, but in reality this property is the time the service allows between client calls (poor, poor documentation Microsoft). Even though, my understanding was that the WCF infrastructure messages exchanged by RM to keep the session alive would count for this receive timeout and would keep my connection alive, but that evidently wasn’t happening.

     

    We then contacted Microsoft PSS and after a while they confirmed that the behavior should be that the infrastructure messages keep the connection alive, but they have changed something in the receive timeout behaviour close to RTM and the end result was that this setting overrides everything else (all other timeouts or sessions) in WCF. It is recognised within Microsoft as a bug, which is good: they know about the bug… but the bad news are that they don’t plan to fix it before WCF version 2.0 as they believe there’s a viable workaround. The workaround in this case is that you can set the receive timeout to an extremely long time span (or System.TimeSpan.MaxValue) or the infinite keyword (that behind the scenes will use System.TimeSpan.MaxValue) and it will produce the expected behaviour.

     

    Moral of the story is: if you ever use WCF reliable messaging and need the session to be kept alive indefinitely you already know: set the receive timeout to something very, very big. 

  • Generics compilation bug in .NET 2.0

    Well, it seems that this week I have been hitting every bug and/or unexpected behavior in the .NET Framework 2 & 3. What is more frustrating is that none of these bugs will be fixed imdiately, some being scheduled for "Orcas" and some for even later releases of the Framework.

     The most importants of these bugs are one on WCF reliable messaging and another one when compiling generics code. The first I will leave for another post and will concentrate on the second bug here.

     I have written a piece of code similar (conceptually) to the following:

    namespace CoreLibrary

    {

        public class BaseClass<T> where T : class, new()

        {

            public virtual string DoSomething()

            {

                T obj = new T();

                return string.Format("The type used is {0}.", obj.GetType().FullName);

            }

        }

     

        public class ChildClass<T, Y> : BaseClass<T>

            where T : SideClass<Y>, new()

            where Y : class, new()

        {

            public override string DoSomething()

            {

                T objT = new T();

                Y objY = new Y();

     

                return string.Format("The two types used for this class are {0} and {1}.", objT.GetType().FullName, objY.GetType().FullName);

            }

        }

     

        public class SideClass<T>

        {

            public string DoSomethingElse()

            {

                return "Did something else!";

            }

        }

    }

    And the program to run that looks like:

    namespace Program

    {

        class Program

        {

            static void Main(string[] args)

            {

                ChildClass<SideClass<object>, object> obj = new ChildClass<SideClass<object>, object>();

                Console.WriteLine(obj.DoSomething());

                Console.Read();

            }

        }

    }

    When I run the above code I get a System.BadImageFormatException.

    It works out to be a bug in the compiler itself as reported here. To solve this, I had to change the BaseClass<T> to the following:

    public class BaseClass<T> where T : new()

    {

        public virtual string DoSomething()

        {

            T obj = new T();

            return string.Format("The type used is {0}.", obj.GetType().FullName);

        }

    }

    By removing the class constraint from T in the base class, everything compiles and works fine. In the actual code I was using in my project, T was constrained to reference types so that I could use some better casting and stuff like that, but in reality I could do just fine without constraining so that wasn’t an issue after all.

    The bug in WCF is a bit more complex and I will post more about that later on as soon as I get time to write the article.

  • Windows Installer MSI packages error code 2869 on Windows Vista

    I was setting up my machine with Vista RTM and have noticed that a few MSI packages would fail to install with an error code 2869 and then a number (two or three) dialog boxes empty of any text. I figured out that these packages are the ones that were interacting with other programs (in this case Visual Studio 2005) and they seem to be denied permission.

    The quick and dirty solution I found to make them install is to create a batch file with the following command:

    msiexec /i "path-to-package.msi"

    Save the file then right-click it and select "Run as Administrator". That makes it work.

  • Busy week at Microsoft

    Well, it seems that Microsoft managed to deliver on their promises and get the new wave of products released early in the month:

    Office 2007 was announced as released by Eric Rudder (Senior VP in Technology Strategy at Microsoft) during his opening keynote in the 2006 TechEd Developers in Barcelona yesterday. He said that it would be hitting the MSDN Subscribers download area shortly.

     Today the .NET Framework 3.0 has been publicly announced both here in Barcelona and on www.netfx3.com and is available for immediate download.

     Finally, yesterday Microsoft announced that they will be releasing Windows Vista to manufacturers today (November the 8th) at 11:00 AM PST, and it should be hitting the MSDN Subscribers download very shortly if not immediately.

     Microsoft has also posted the first public CTP of Visual Studio "Orcas", the next release of Visual Studio, in a Virtual PC image available for MSDN Subscribers. They have been demoing the new Orcas tools quite heavily here in the TechEd and it is nice that we actually get to play with all that stuff.

  • Windows Vista and Office 2007 Beta 2

    Hello there,

    Well, it seems that Microsoft decided to quietly release Windows Vista and Office 2007 Beta 2 for MSDN and TechNet subscribers.

    By the product keys made available on the MSDN Subscribers download area it seems that Windows Vista Ultimate Beta 2 is available (as well as Home Premium Edition), so it should be packing all the features that have been currently made available.

    Can't say more on what are the contents of these releases because the downloads are quite big (DVD images of 3GB each), but a little more information can be found on Microsoft's website (http://www.microsoft.com/windowsvista/default.aspx).

    I will be posting back as soon as I manage to install these.

  • YEYYYYY!!!!! RTM DAY!

    Cool! Today is RTM day at Microsoft. They're sending to manufacturing SQL Server 2005 and Visual Studio 2005 and guess what? They are making it available at MSDN subscribers downloads too. I'm already downloading my copy of SQL Server 2005 Developer RTM and just waiting for the Visual Studio 2005 TS get there as well (the professional only is available as I write). BTW, there is an ISO image of a Visio for Enterprise Architects for Visual Studio 2005. As I never heard of it before I'm downloading it to see what's that about.

  • O2 tech support and Microsoft Voice Command

    Well, this weekend I discovered that my new HTC Universal (O2 XDA Exec) has a bug that if you have it connected to your computer with ActiveSync on and try to make a phone call, it doesn’t open the phone tool. After that, you can even unplug the device from the computer and will still not open the phone tool until you soft-reset it.

    I have then called O2 trying to report the bug. The dialogue with the O2 support person was something like this:

    Me – Hello, I have just got a new O2 XDA Exec a couple of days ago and I think I have found a bug on it, so I would like to report that.
    O2TR – What is the problem that you’re having?

    I explain the ActiveSync problem in as much detail as I can.

    O2 – OK, I will send you a new phone, then.
    Me – Look, I really don’t think it is a device problem. I think it is a software glitch and I was just looking to report it so you can get fixed in the next software release.
    O2 – Yeah, but out police is that if the customer has any problems with his device on the first 28 days after the purchase, we replace it.
    Me – Well, but I wasn’t really willing to replace my device, as I have installed tons of software and configured that to my liking.
    O2 – I’m sorry, Sir, but we have to replace your device. It is O2’s policy .
    Me - Can I just send you the new device back when I get it?
    O2 – If you do so, Sir, we can’t provide you technical support any more.
    Me – Can’t you just forget that I have called you? It never happened.
    O2 – Sorry, Sir, it is O2’s policy to replace devices in such cases. I’m sending you the new one.

    The result is that I will be getting today a new XDA Exec and will have to replace my perfectly functional one, reinstall all the software I’ve got there, re-download all the settings, e-mails and stuff… And will probably find the bug again on the new one. I can't believe that it is cheaper to O2 to get have a perfectly functional device replaced and sent back to factory just because they can't provide adequate technical support.

    In the other hand, I have tried Microsoft Voice Command UK 1.5 during the weekend. The first thing that comes to mind when I think about that software is: WOW. It is not only a very good software for general users, but it is a very interesting achievement from a developer's point of view. The software is just brilliant. 

    For starters, this is a voice recognition software that allows you to control many Pocket PC functions. You click a button, speak to it and it does what you want. What is different here? Well, two things: 

    1 – The whole time I have spent setting the application up was the time to install it on the device and configure which button I wanted to use to activate it. The software needs zero training whatsoever.
    2 – You can actually dialogue with the software. If you are unsure of what you can do, just ask: “What can I say?” and the software will help you through.

    Now, some of you know that I’m not British and I have quite a heavy accent and still the software can recognize what I say like 90% of the time. My wife and a couple of friends have tested it as well and they could command the device straight away, with natural speaking. The software can be used to make phone calls to contacts on your contact list or you can just ask it to dial a phone number and it will dial the number for you. If you ask to call a contact that has multiple phone numbers, it will tell which numbers are available (mobile, home, office) and will ask which one you want. You can also open programs; you can play music only by saying: “Play Nirvana” or “Play rock music” and it will do the job.  

    Another interesting aspect of this software is that it is really light in processor and memory footprint. It doesn’t remain active all the time and when you press the button to activate it, it gets available very quickly, unlike some other voice recognition software that would be heavy even for a PC.

    I just wonder why Microsoft doesn’t make it part of the default Windows Mobile set of features. With that software you can really use a Pocket PC phone comfortably with one hand. Now that I tried it I know I can’t live without it and already purchased my copy.

  • My new WM 5.0 Device

    Well, I have spent nearly 11 months without a Windows Mobile device (after I have given away my Motorola MPx200 and my iPAQ H5550 when moving to the UK) and I was really hard-pressed to get a new one, but didn’t want to buy anything that I would want to change in a couple of months, so I decided to wait for the new generation of Windows Mobile 5.0 devices.

    Last week I finally got hold of my O2 XDA Exec, a branded version of the HTC Universal Pocket PC Phone Edition. I was really looking forward to that device since I first read about it several months ago.

    I have considered getting an HTC Wizard, which is smaller, but the list of features just didn’t cut it for me: the Universal was the device I wanted. I have chosen O2 the deal I got. I have ordered my device exactly on the same day they’ve made it available on their website (to days ago), so I was lucky enough to get them in stock and get one shipped to me in the same day.

    The package is really neat. It comes in a quite small box with two drawers that open one to each side. The contents are the device itself, battery, battery charger, wired headset, manuals and CDs. The first CD comes with the usual Microsoft pack of ActiveSync 4.0 and Outlook 2002. The second CD comes with Spb GPRS Monitor, ClearVue PDF Viewer and the modem driver to install on your PC, so you can use the device as a modem.

    After popping in the USIM (3G) and battery in it and turning the device on, I was welcomed by the normal “getting started wizard” where Windows Mobile calibrates the screen and show you how to use the stylus. After finishing such wizard the device connects to the O2 network to download the customizations. These customizations, other than the network connections settings, profiles, additional programs and links to O2 web sites, install also a different home screen, which slows down the device quite heavily and freezes all the time. After a couple of hours using the device I have disabled such software, rolling back to the default Windows Mobile interface and the results were amazing. The device gets much quicker and things work just as expected. You don’t loose any functionality also, as you can still access all the bundled programs from the Programs menu.

    Externally, the device looks cool. It is dark and has a quite classy look to it. It is certainly big, but not as big as one might expect. I have also purchased a Bluetooth headset (Sony-Ericsson HTH-662) to use with it, as I don’t see the point of holding such a brick against your ear to talk and I find it really cool to be able to talk to someone and still use the unit to browse the web or work on documents.

    The screen is very bright, has sharp images, the VGA resolution just looks awesome and is very comfortable to use. The keyboard is one of the things that set this unit apart: You can hold the unit and use the keyboard with your thumbs, or you can put the unit on a desk and type with your other fingers as you would in a laptop keyboard. The input is very comfortable and you will become addicted to using that quicker than you expect. The addition of the soft keys in WM 5.0 for PPC-PE also increases the usability of the unit, as you don’t depend as much on the stylus as in WM 2003 SE devices.

    Software wise, well, the unit comes with Windows Mobile 5.0 for Pocket PC Phone Edition. I haven’t had enough time to evaluate all the improvements so far, but it looks nice. One thing I have noticed, though, is that the soft keys are a very good addition and the Inbox application is much more powerful, mainly on the attachments management.

    Connect the device to wireless network worked nicely both at home and at my client’s office, having no problems whatsoever. Bluetooth pairing both with my laptop and the BT headset also went just fine.

    Browsing the web on that device is cool, mainly because now it is very comfortable to type addresses, the landscape screen orientation improves the way you see the web pages and the VGA screen means that you can use smaller font sizes getting more out of the space you have available.

    The in-built photo camera is nice, having nice quality, flash and being very easy to use. The movies are also quite cool, even if it looks like the images are been stretched when you move the camera around. I wasn’t able to test a video-call, as I haven’t found anyone with a 3G device that wants to be on the other side, but I will do that as soon as possible.

    After installing Skype I had a few problems, like the device not initializing and stuff. Removing Skype it just came back to normal. I have never used Skype on other devices, but in the XDA Exec it doesn’t appear to work very well. Other than closing all the time and not being able to keep a connection, the voice quality during the call is quite bad the device becomes much more unstable.

    I have installed the following software on the device:

    • Adobe Acrobat Reader 2.0 – Works fine, doesn’t support landscape very well, though.
    • DeveloperOne AgendaFusion 7.25 – Not compatible, doesn’t work.
    • Ilium Soft eWallet 4.1 – Works fine
    • Ilium Soft NewsBreak 1.1 – Works fine
    • PocketTV 1.1.5 – Works fine
    • Resco Explorer 2005 5.22 – Works fine
    • Spb PocketPlus 3.0 – Works fine
    • Spb GPRS Monitor 2.4 – Works fine
    • WordBook English Dictionary 1.1 – Works fine
    • Microsoft Voice Command UK 1.5 – Works fine

    I will be waiting for DeveloperOne’s update for AgendaFusion to work on Windows Mobile 5.0, as I can’t live without it. Just love it as a PIM.

    Battery life is great. I can live the device in stand-by with WI-FI off and Bluetooth on and it will last for 24 hours consuming only 5% of its battery. When using it heavily on WI-FI, it will last me for something between 4 and 5 hours.

    All in all, the device is what I expected. It is not without its flaws (size and weight mainly), but it does what I wanted. After removing the O2 Active UI it became much snappier and WAY better to use.

    Now, as Keni mentioned, I’m waiting to get my hands on the i-mate SP5, which I have ordered for my wife. She never had a Windows Mobile device, but after having used mine she was keen of getting one for her as well.

    Below are some quick pictures I took from the device. Don't pay attention to the quality as they were really quick.

    IMG_0973.jpg

    IMG_0974.jpg

    IMG_0975.jpg

    IMG_0976.jpg

    IMG_0977.jpg

  • PDC: “The Goods” look more like “The Bads”

    Well, Microsoft has been saying for weeks now that we would be astonished by “The Goods”. “The Goods” is the DVD pack containing the betas and latest releases of most of Microsoft software under development.

    Well, we got the pack right on Tuesday, after the opening keynotes. With the pack we got a note stating that due to an imaging error, the disc 2 (Visual Studio 2005) wouldn’t install. We should actually copy the contents of the disk to the hard drive and launch the setup from there.

    Then I opened the package and guess what? One of the six disks was missing. After going back to the materials desk, they said that it actually was missing on all the packages and they would distribute the missing disk today.

    Then I started trying to install the contents of the disk 4, which is WinFX and gu