System.ServiceModel.FaultException in IIS

Had a very strange error the other day when migrating a project from using the Visual Studio IIS Express to the local IIS.

The project was a WebAPI that interfaced down to a Microsoft Dynamics CRM 2015 instance on the same box and had been working well within the Visual Studio environment.  However, as soon as the project was deployed to the local IIS instance the connection to the CRM was failing with a rather obscure System.ServiceModel.FaultException.  Unfortunately, there was little else in the exception details to go on and an initial Google search yielded little help aswell.

After many different tests to try and isolate the issue I finally found the reason for the failure which was the authentication was failing.  Again, after a few more tests I still couldn’t get the authentication to work, but eventually came across one guys answer to a similar problem on Stack Exchange (  Scroll down to the first answer (Sixto) and he mentions that you need to change the AppPool identity!  Voila!  The default Identity setting is ApplicationPoolIdentity which is great if you are simply reading and running the code in ASP.NET pages, however this won’t allow access to databases etc… and you need to change the identity to a user that has been granted access to whatever resource your webpage is trying to gain access too.

Here is a page with some more details on the different web servers Visual Studio can use along with the advantages and disadvantages of each.




Asset Editor

In a previous post, we mentioned one of the many challenges we faced when implementing this product for the client.  At this stage the product is under trial to prove the concept for management in order to progress to the next stage of roll-out.

The next stage of the product would be to essentially clean up, fine-tune and hopefully re-engineer the product to better suit it to the environment that it will ultimately live in.  At the start of the project, the client didn’t have some necessary things in place for connecting to ArcGIS, so a different method was used to implement the mapping and linear referencing system.  Unfortunately this older system required WinForms to be used when we would have preferred to implement in WPF as the tablets that were to be used were using Windows 8.1 (comparison: old but still valid).

As is the case with many initial projects that are under time constraints as well as technology constraints, we reflect on the past work as we progress and see ways of improving.  Given all of the initial technological hurdles have been resolved and the product works, the re-work of the application will result in a more robust and cleaner application for the client.  Thankfully with our application architecture, we built it using an MVP pattern, so the majority of the business logic code is separated from the view therefore making the transition to a WPF application will be so much easier.

ArcGIS API for Javascript and CEF

With our latest project (Asset Editor) we came up with a number of challenges to overcome in order to deliver a successful application.  Probably the biggest challenge was the integration of a live map using the client’s ArcGIS.

Normally the implementation of a view of ArcGIS in Chrome or IE is simple given the excellent API supplied by Esri, however we needed to have this view within an application rather than a web browser.  In the past we used Microsoft’s WebBrowser control, but given the restrictions in place on the client’s device and the restrictions on the API for ArcGIS, we needed to look at another solution.  To achieve this we looked at CEF and CefSharp which can be used without installation and comes with a fantastic  set of DevTools amongst other benefits (speed etc…).  Implementation of CEF wasn’t necessarily straight forward, but after creating some test apps to prove that the concept would work, we were able to create the same framework that we would normally have created using the old WebBrowser control.  The support for Javascript integration is great and really easy to implement and allowed us to nicely integrate the control into our code and provide the necessary couplings between web browser, ArcGIS and the back end.



Corridor Tracker

During some work on a new project for a client we needed to be able to define boundaries for physical map areas (e.g. rail corridors).  Given that the project was for rail vehicles, there was only certain areas on the map where the vehicle could enter and exit these boundaries.

We used Google Earth to define these boundaries using polygons that covered the boundary positions for both entry and exit (separate ones for each).  The polygons were structured in Google Earth to provide a simple hierarchy that would provide extra information where needed (e.g. corridor name, owner, operator etc…).  The polygons were then exported to the usual KML file.  Given that the KML file is a standard and the format is in XML we then simply imported the file into our project to generate data type classes that could read in the file.  Understanding of course that a change to the KML specification and therefore a potential change to the format would break the import!!!  This particular case would be handled externally to these generated classes.

With all of this in place we were able to easily provide the client with a configurable definition of their rail corridors that could be read in and subsequently viewed in the applications Google Maps window and processed according to the vehicles current position.

AGMS Controller

We’ve been working on the AGMS Controller for some time now with the QueenslandRail contract and lots of good stuff has gone into it.  However, we recently added station and timetable reporting (On-Time-Running) which has been an interesting piece of work.

Both AGMS systems run on the North Coast line and Mount Isa line in Queensland and given the vast distances of the journeys (> 1000km) the train journeys run over night.  We needed to come up with a system that would first track the vehicles through configured locations (stations) and actively determine what timetable the vehicle was running too.  This would be relatively easy if we just consider the existing vehicles and their simple timetables, but we wanted to make the system capable of handling the suburban system if required (as QueenslandRail have a pretty basic method of determining On-Time-Running….and potentially fudgable!!!!!).

The resultant system needed to handle the following circumstances:

  • running through the night and into the next day;
  • tracking late trains to the correct timetable, as the suburban timetables run every 15 minutes on some lines;
  • handling missing a station (bad GPS, loss of power etc…);
  • handle trains that don’t complete the expected run (break-down, turn-back);

The timetable matching algorithm was based on a number of parameters that scored each timetable as each station was reached.  If any one timetable matched a number of criteria (score over 50% being one), then it was determined to be the correct timetable and emailed out an End of Run Report (see the screenshot below)

AGMS2TimetableThe system primarily used our configurable StateEngine library to implement 2 continuously running process.  The first was one process to take incoming GPS data, match it to configured stations and fire events to inform subscribers that a station had been reached.  The second process subscribed to the station event and used this information to compile and score all of the configured timetables within the system, with the ultimate goal of firing a timetable complete event.

Subversion, TeamCity and Trac

A while back aftermoving house, I thought it time to revisit our source control and Continuous Integration setup. We had been using CSV, CruiseControl and Bugzilla for the best part of about 10 years without any major issues, but we guessed you can’t improve yourselves if you don’t try new things, so here we are!

After much searching we plumped for the combination of Subversion, Jet Brains’ TeamCity and The Trac Project. First off the installation of each was quite a breeze compared to when we did this 10 years ago. Yes things have moved on, improved, Google etc… but it was nice for installations to go without a hitch. Having said that a few sites did help along the way.

For installing and setting up Subversion, we found this site extremely useful. Also, for any out there new to Subversion or indeed source control, this site here is a good resource

TeamCity (continuous integration), well there isn’t too much to say other than simple! We’ve been using ReSharper since about 2004 and have always loved it and once again Jet Brains have delivered.

Trac is a wiki and issue tracking system and as with the others, this was simple to setup and use.

WinForms Screen Capture

For a recent project we’ve been working on we needed to get a screen shot of a form and it’s contents. After much checking on the net for some sample code, all of which used GDI32 and User32 calls, we gave up looking and decided to investigate ourselves.

In the end it was so simple and clean that we just can’t believe that this isn’t documented that well anywhere on the web. The code below is an extract of our code that takes the forms position on the screen, creates a bitmap of the contents of the screen from co-ordinates passed to it and then saves the resultant screen shot to a file

using (Bitmap bitmap = new Bitmap(ParentForm.Size.Width, ParentForm.Size.Height))
using (Graphics g = Graphics.FromImage(bitmap))
g.CopyFromScreen(new Point(ParentForm.DesktopLocation.X, ParentForm.DesktopLocation.Y), new Point(0, 0), ParentForm.Size);

bitmap.Save(@”C:\test.jpg”, ImageFormat.Jpeg);

Enjoy 🙂


Ajax comes to

The goal of the website is to be the oracle of information about Australia for us UK poms and to help them in the emigrating process. To that end, one of the things we needed to do was also supply real-time information about Australia from the point of view of weather, money and time.

Initially, the website was set up to actively get this information from a variety of sources and simply display on the page via the master page. However, the weather information in particular, comes from a slowish website that was killing the inital load time of the site.

The solution was simply to implement Ajax calls to get the information required in an asynchronous manner. Using the generic library that we created to demostrate Ajax calls on our main website, we were able to implement the calls for all of the data in one quick afternoon. The result is a quicker and more pleasing experience.

Showing a Windows form full screen

Ok…. quite simple you might think! And yes it is, but only if you know how!

For a small project that we are working on at the moment we needed to show a Windows Form in full screen mode without the taskbar etc… It is quite simple in the end but needs a couple of Win32Api calls, but that is simple enough. The one thing that is easy to forget is that you need to set the FormBorderStyle property for the form to None, otherwise you will still have the menu bar showing.

To acheive the full screen mode create a simple class with the code below in it

[DllImport(“user32.dll”, EntryPoint = “GetSystemMetrics”)]
public static extern int GetSystemMetrics(int which);

public static extern void SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int X, int Y, int width, int height, uint flags);

private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private static IntPtr HWND_TOP = IntPtr.Zero;
private const int SWP_SHOWWINDOW = 64;

public static int ScreenX
get { return GetSystemMetrics(SM_CXSCREEN); }

public static int ScreenY
get { return GetSystemMetrics(SM_CYSCREEN); }

public static void SetWindowFullScreen(IntPtr hwnd)
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);

Then in your application simply create a new instance of the form and call the Show method on the form.

Form form1 = new Form();
form1 .Show(this);

Then finally create an OnLoad handler for the form and call the SetWindowFullScreen method on our helper class and that is it.



New CodeConsults website – Emigrating To Oz

We’ve recently started a new project website called Emigrating To Oz

Its a site centering around providing a resource of information for people wishing to emigrate to Australia, but its still in its infancy and we are targetting a Q2 2008 release with all the bells and whistles, but in the meantime the site is live so that we can begin getting it indexed and tested.

There’s plenty of work to do and content to add and we’re hoping that in time it will become an excellent resource for us Poms who are looking at possible life Down Under.