Windows Phone 7: Custom Tool Error failed to generate code for service reference

Stumbling here because you are having trouble updating a service reference in your Windows Phone 7 application? Are you getting a warning that reads something like this?

Custom tool warning: Cannot import wsdl:portType

Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter

Error: Could not load type 'System.Runtime.Serialization.DataContractSet' from assembly 'System.Runtime.Serialization, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

Or this?

Custom tool warning: No endpoints compatible with Silverlight 3 were found. The generated client class will not be usable unless endpoint information is provided via the constructor.

I’ve had this problem several times now, and each time I’m stumped why this happens. So I am writing down what causes this once and for all so that I don’t keep forgetting. Here it goes …

Frequently I am wanting to consume OData feeds within my apps. An easy way to do so is to use the Open Data Protocol Client Library available on CodePlex. The library contains the System.Data.Services.Client.dll assembly that you reference in your Windows Phone application project.

This assembly is trouble when trying to mix with service reference generation. I’ve seen posts that talk about deselecting the “Reuse Types in Referenced Assemblies” option when generating the reference, but this is not exactly a solution I am happy with. What if I do want to reuse types?

The best workaround I’ve come up with so far is to generate my service references in a separate Windows Phone Class Library project that does not reference the System.Data.Services.Client.dll. I then add a project reference to this class library in the WP7 application project. Finally, I need to copy the system.serviceModel entries generated in the class library’s ServiceReferences.ClientConfig file to the WP7 application’s ServiceReferences.ClientConfig file.

It is also probably not a bad idea to include any OData generated proxies along with the System.Data.Services.Client.dll in a separate Windows Phone Class Library project as well.

I hope this post saves you some headache as it will for me time and time again.

Using the Windows Phone 7 Bing Maps Control with MVVM Light

I’ve recently adopted MVVM Light as my MVVM framework of choice for both Silverlight and Windows Phone 7 development. Why use frameworks like MVVM Light? First and foremost, to achieve clear separation of concerns between the application UI and the backing data. While this goal seems fairly elementary, pulling this off in practice can be quite challenging due to how Microsoft has designed some of the native controls. The Bing Maps control is one good example.

In my scenario (which I would guess is a fairly common scenario), I am data binding multiple locations as push pins on the map. Clicking on a push pin should cause the application to navigate to a details page (a responsibility of the view), but also the corresponding view model for the details page needs to be notified of the location in context. This is where things get a little tricky and the MVVM Light EventToCommand behavior and Messenger features come to the rescue.

To begin, I’ve put together a simple map view shown below. Notice the two interaction triggers on the map push pin. The second trigger is the navigate action … straightforward enough. The first trigger is the MVVM Light EventToCommand behavior that invokes a command called ‘SelectCommand’ on the bound location.

FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<c:GeoCoordinateConverter x:Key="GeoCoordinateConverter" />
<Grid x:Name="LayoutRoot">
<Maps:Map ZoomLevel="10" Center="{Binding Path=MapCenter, Mode=TwoWay}">
<Maps:MapItemsControl ItemsSource="{Binding NearbyLocations}">
<Maps:Pushpin Location="{Binding Converter={StaticResource GeoCoordinateConverter}}" >
<i:EventTrigger EventName="MouseLeftButtonDown">
<gs:EventToCommand Command="{Binding Path=SelectCommand}" />
<ic:NavigateToPageAction TargetPage="/Details.xaml"/>

For the sake of brevity, I am going to skip the Main view model, which contains a MarkerViewModel-typed ObservableCollection property called NearbyLocations that gets bound to by the MapItemsControl’s ItemsSource property shown above.

Now lets take a look at the MarkerViewModel class that serves as the view model for a single location on the map represented by a push pin. Notice the implementation of the SelectCommand property, which simply fires a PropertyChangedMessage. This will allow the details view model which listens for this particular message to update its context when the push pin is clicked.

public class MarkerViewModel : ILocation
public Marker Marker { get; set; }
public double Latitude
get { return Marker.Latitude; }
public double Longitude
get { return Marker.Longitude; }
private ICommand _selectCommand;
public ICommand SelectCommand
if (_selectCommand == null)
_selectCommand = new RelayCommand(() =>
var messenger = Messenger.Default;
new PropertyChangedMessage<Marker>(null, Marker, "SelectedMarker")
return _selectCommand;

Finally, in the constructor of the Details view model we register to listen for the Marker-typed PropertyChangedMessage message.

public class DetailsViewModel : ViewModelBase
public DetailsViewModel()
if (IsInDesignMode)
Marker = new Marker
ID = 1,
Title = "Design Mode Marker Title"
message =>
DispatcherHelper.CheckBeginInvokeOnUI(() =>
Marker = message.NewValue;

public const string MarkerPropertyName = "Marker";
private Marker _marker;
public Marker Marker
get { return _marker; }
if (_marker == value)

var oldValue = _marker;
_marker = value;

// Update bindings, no broadcast

To sum up, I’ve demonstrated two really great features of the MVVM Light framework – the EventToCommand behavior and the Messenger features – and how these features can be used to successfully pull off the MVVM pattern with the Windows Phone 7 Bing Maps control.