Tim Murphy's .NET Software Architecture Blog

August 2011 Entries

WCF Deployment To IIS

If you are developing you WCF service for web service deployment under IIS and coding with the Visual Studio web server you are in for a rude awakening when it comes time to deploy your solution.  Ok, so that is a little over dramatic, but there are a few steps and precautions you need to know about.

Below are the main steps to deploying your application to IIS assuming WCF is already installed and registered.

The first step is to create an application pool.  Make sure that for your .NET 3.5 WCF service that the application pool is set to the 2.0 .NET framework.


Next you need to create a new site.  The application pool for this site should be the one that you just created.


So here is that precaution I was talking about earlier.  You run into a number of hurdles if you try to share a site with a WCF service and another application.  The easiest way around that is to deploy each service project to its own site.  I am still working on how to get them to co-exist and will post that information when I have it resolved.

Lastly, at a minimum you need to copy the bin directory, web.config and .svc files to the physical directory that your new site references.  This configuration should work in most cases.  In the future I will address some of the common alternate configuration.  Stay tuned.

Creating Emails For Windows Phone 7

There are many reasons that you may want to add email capability to your Windows Phone 7 application.  There are a number of ways you can communicate information out from an application. 

The mechanism for sending email from your WP7 application is the EmailComposeTask API.  The difference between this API and the one that you would use for an ASP.NET application is that it opens a screen to allow the user to select an account to use and then creates a message which the user then has to send.  This makes sense since the we are talking about end user applications and not server processes.

Below is a quick look at the code required to send an email using the EmailComposeTask.

EmailComposeTask emailTask = new EmailComposeTask();

// Not setting the "To" property will prompt the user
//emailTask.To = "jqsample@somemail.com";

emailTask.Subject = "Your subject";

emailTask.Body = "Here is where the body goes.";

There are two drawbacks that I would like to see addressed.  The first is that you cannot create a HTML body.  The second is that you can’t attach a file.  Hopefully these will be addressed in future versions.

The Power Of Windows Phone 7 Tasks

One of the things that is important to learn when you are developing any application is how it will interact with the environment it lives in.  I’m not talking about simply interacting with files or database but with major resources.  With WP7 there are a number of things such as the photos, browser, maps and the phone itself that your application may be concerned with.

The WP7 development API includes a number of access points to give your application greater reach.  These APIs can be found here.

They APIs fall into the following main areas:

  • Contacts
  • Bing Maps
  • Camera
  • Email
  • Market Place
  • Messaging

In future posts I will explore some of these APIs.  Stay tuned.

WCF Service Development Basics

Part of the fun of being a consultant is that the technology you use changes from day to day.  Recently it is WCF which, while knowing the concepts of since it came out I haven’t used up until now.

The nice thing is that it really isn’t any harder to develop for than a normal ASP.NET web service.  A couple of the attributes change and which project type you start with is different, but it is still message based services.

Just like the method of a web service needs a Webmethod attribute a method in a WCF service requires a OperationContract attribute.  The main difference is that you start by defining your operations in an interface.  Once you have an interface like the extract below you simply create an implementation class based on the interface.

public interface IMyServices
MyCustomReturn GetMyData(MyDataRequest dataRequest);

To get your WSDL and its associated XSD to generate in a way that is intelligible by other developers you need to effectively use the DataContract and DataMember attributes.  The resulting class will look similar to the extract below.

public class MyCustomReturn
public string UserEmail;
public string BusinessUnitId;
public ClientAddressInfo ClientAddressInformation;

Once you have this base the rest of the development is straight up .NET.  The other thing you need to know is how to get at your WSDL and XSD.  The WSDL is the easy part.  Add “?wsdl” to the URL for your .svc file.

Finding the XSD isn’t that difficult.  If you look in the WSDL definition there is a tag for <wsdl:types>.  Within this tag you will find an <xsd:imports> that ties back to your service’s namespace.  Normally this is just adding a query string of “?xsd=xsd2” to your service URL.

Lastly you need to learn how to use the WCF Test Client.  The one way I have found to launch it is to make sure your service code file is active in the Visual Studio editor and hit F5.


This tool will allow you to do most of you basic testing of the service you just built.


Windows Phone 7 TextBox InputScope

I originally started looking for how to make a TextBox have autocomplete capability.  Strangely all the articles said that it couldn’t be done.  The last thing you want is for your applications to make your users struggle entering information when every other application gives them a quicker entry method.  So what is the solution?

The TextBox tag has an InputScope property which if you set it to Text it builds a dictionary list as the user types.  For the other InputScope types it mainly changes the keyboard defaults.


In all this one small change can have a large impact on the usability of your app.

Chicago IT Architect Group August 2011 Recap

We had a full house this month with a lot of interest in the SOLID principle.  SOLID is one of those topics that should be basic study in all of our schools.  Of course along with a large crowd comes a lot of discussion.  There were debates as to how much each individual principle has merit and how to properly apply it.  This is the lively discussion that really makes me enjoy organizing these presentations.

Visit Michael Kappel’s web site here.

Handling Windows Phone 7 Back Button

When you have an application that navigates to more than one level of pages you find situations where you don’t want to go back to the previous page.  Originally I was thinking that the answer was to capture the OnBackButton event and force the navigation back to the main page, but through several posts I found that this would not pass certification. Here is a link that really helped to figure out a more appropriate solution.

To be a little more complete here is example code that you can use use for both the intermediate page and the main page.

Intermediate page code:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

App app = (App) Application.Current;

Main page code:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
App app = (App) Application.Current;
app.MustNavigateBack = false;

Practical Window Phone 7 ListBox Usage

Almost every example of a Silverlight ListBox that I have found merely shows how to get data bound to it, not what to do once you get it there.  What good is a ListBox that you can’t get a reference back from?

The quickest practical way is to hold your original datasource and use the index of the selected item as you key back into your data.  It isn’t pretty and you wouldn’t want to take this approach with large amounts of data, but then again a mobile device isn’t meant to display large amounts of data to begin with.  Here is the sample of the code to retrieve an object from a List.

if (listBox.SelectedIndex > -1)
var tempObject = _myObjectList[listBox.SelectedIndex];
// Do something important like delete the object
// or navigate to another page using the object data

Of course there are other options, especially if this is a navigation scenario.  You could use a ListBoxItem template that would contain a HyperlinkButton and bind the identifier for your object into the URI query string.  I am still looking for other more elegant solutions but these options can help get your application moving.

Sending Large Arrays With WCF

Windows Communication Foundation is a powerful tool for building contract based messaging.  As with most powerful technologies with flexibility comes a fair amount of complexity.  I ran into one of these situation while trying to send files as part of message in the form of a byte array.

In itself this is a simple concept.  The problem is that the default configuration of WCF is setup to protect us from denial of service attacks to the best of its ability.  In order to achieve this it is setup for relatively small message sizes.  So bump the buffer, right?  Well it isn’t quite that simple.  Below I will outline the configuration changes that have to be made to both the service and the client in order to accept messages that contain large arrays specifically.

The service configuration requires that the message size and array size need to be increased.  To be safe I increased the size of all the values.  You will note though that you will not normally see the binding spelled out in an auto-generated config file.You have to add the wsHttpBinding section.

<binding name="wsHttp" maxReceivedMessageSize="50000000">
<readerQuotas maxArrayLength="50000000" maxStringContentLength="50000000"/>
<service behaviorConfiguration="MyServiceBehavior"
<endpoint bindingConfiguration="wsHttp" address="" binding="wsHttpBinding" contract="IMyInterface">
<dns value="localhost" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

Since the WCF Test Client is rather limited to how data can be entered I ended up creating a Windows Forms application as a test harness.  The configuration for the client is included below.  Just like the service configuration I upped all of the values.

<binding name="WSHttpBinding_IQcsServices" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="50000000" maxReceivedMessageSize="50000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
<readerQuotas maxDepth="50000000" maxStringContentLength="50000000" maxArrayLength="50000000"
maxBytesPerRead="50000000" maxNameTableCharCount="50000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />

Hopefully these settings will help shortcut someone’s search to getting large WCF messages to work.

Windows Phone 7 Key Silverlight Page Events

Often times you want to you need to update a page when you enter it or save information automatically when you leave it.  When you look through the events list on the property page you won’t find an event that occurs at those points in the page lifecycle.  Intellisense is your friend in this case.  The events OnNavigateTo and OnNavigateFrom can be overridden to give your application the required functionality.  Below is a sample signature for OnNavigateTo.

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

//TODO: Place your code here for when the page is navigated to

More Windows Phone 7 Panorama Notes

The saga goes on.  There is always something more to learn.  While I thought that ManipulationCompleted would do the trick from me it turned out it won’t.

It turns out that if you want to figure out what PanoramaItem you are on when the user navigates between PanoramaItems the SelectionChanged event in conjunction with the SelectedItem on the Panorama works pretty well.

private void Panorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
PanoramaItem item = (PanoramaItem)Panorama.SelectedItem;
if(item.Name == "PanoramaItem1" || item.Name == "PanoramaItem2")
// Process the PanoramaItem here

This combination gives a good technique to identify when the user has swiped the Panorama and which PanoramaItem is now showing.

Now back to your regularly scheduled programming.

Windows Phone 7 Panorama Page

Creating a WP7 application with a Panorama page is fairly simple.  Teaching it to do tricks is another thing altogether.  As with most development controls the key is to learn the event model along with the object model.

Knowing what manipulation means, when it happens and what the different levels it occurs at can be a great benefit.  This was the case when I wanted to make sure that a particular item was updated before the user got to a particular PanoramaItem.

The visibility of a PanoramaItem does not change when you navigate away from it and so far I am still looking for how to determine which one is being viewed by the user.  My work around was to utilize the ManipulationCompleted event of each PanoramaItem to update the isolated storage and the PanoramItem that contains the summary of the other items.  This won’t work for all situations, but it is effective for my purposes because it happens on each item individually.

private void PanoramaItem1_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
//TODO: Something meaningful here

private void PanoramaItem2_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
//TODO: Something meaningful here too

Given that this solution still leaves some control to be desired look forward to more posts on the subject.

Integrating Cloud Application In Your Enterprise

More and more companies are turning to companies who host cloud applications such as SalesForce.  I may be mistaken, but I thought we used to call these ASPs (Application Service Providers).  Whatever we call them they are the latest trend in IT services especially in larger corporations.

So what does this trend mean for those of us who design, build and integrate systems?  It means a new set of challenges, considerations and opportunities.  The more you know about these areas going into a project the more likely it will be that you succeed.

The first thing that you will need to understand is that you are adding an extra team to your project.  Along with this goes the need for better communication skills, both written and verbal.  This starts with a number of assumptions that should be added to your project plan as to what is expected from the application provider and continues with the need for regular status meetings to ensure that they are making progress on your requests.

If you work for a consulting firm like I do conversations now have to include all three parties and everyone needs to be on the same page.  Handling expectations on all sides becomes a critical task.  On the other hand these situations can create an opportunity for you to gain a new partner by helping each other to gain more business.

Once you get past the relationships the biggest challenges you will run up against is that your data no longer resides exclusively in your enterprise.  This means if you need to share that data with the provider you are in for a ride.

There are a number of considerations that need to be made in relation to data.  How does data need to be shared?  Will it be bi-directional?  How fast does it need to be refreshed?  Real time data becomes costly to transport over the network and generate security concerns especially if the data includes personal information.  And the list goes on.

In the end this is not a condemnation of or an endorsement of cloud applications.  It is a wake up call that you should not make decisions to use them lightly.  Don’t just weigh the cost of the services, but all the costs associated with the new relationship and make an educated decision.

August 2011 Chicago Information Technology Architects Group Meeting

Our summer break is over and with the dog days of August we are getting back to setting up presentations of interest to Chicago area IT Architects.  This month we will have Michael Kappel presenting on a topic we have been trying to get organized for a while.  SOLID is an acronym for five object oriented design and development principles that everyone should know.  Michael is going to give a platform agnostic discussion of these five key principles.  Please join us by registering below.

Register here