Archive for category Uncategorized

My Windows Azure Caching Service talk from DevConnections

I just presented my Windows Azure Caching Service talk. Thanks to everyone who attended. The audience was small, but I love that you all asked so many great questions. Here are the slides and demos from the talk. I’ll be giving this talk again at the Midwest Cloud Computing User Group in the Chicago area on November 15. You can register for it at

The slides and demos from the content at DevConnections is here.

Leave a comment

Talk and demos from CNUG, AppFabric Talk

Last night I had a chance to speak about Windows Azure AppFabric at the Chicago .NET Users’ Group. Thanks to everyone who came out! I had a great time. A few of you really wanted the slides ASAP. I’ve cleaned out my keys and namespaces from the demos, so they don’t run at the moment (but they will build!). You can get them here:

You’ll need to install a few things and create a few accounts if you want to run any of the demos:


1. Getting started links for Windows Azure:

2. Windows Azure AppFabric SDK 1.0: (for production AppFabric)

3. Windows Azure AppFabric SDK 2.0: (for the CTP bits: queues, topics, etc.)

4. More training on Windows Azure: (10 day free trial– totally worth it, but I am an instructor there too;) )

Leave a comment

AppFabricLabs and the ServiceBus

This week, the Windows Azure AppFabricLabs was updated. The major updates are that the Service Bus labs environment now uses v2 of the Access Control Service and topics/queues have been created. This pushes the number of queueing solutions on Azure to 3:

* Queue Storage

* Message Buffer

* Queues

The main difference between the types of storage relates to size and usage patterns. Queue storage allows for messages up to 8 KB in size and is primarily intended for applications running on Azure. The service only accepts one type of credentials, and you probably don’t want to share those.

The Message Buffer stores messages of up to 60KB for about a minute. It is great for volatile queues as a short lived rendezvous point for exchanging messages. This service lives on the Service Bus and allows for authentication with the Access Control Service.

The Queues implementation in the Service Bus allows for larger messages (up to 256 KB) which can last for a longer period of time. Interacting with the queue feature is pretty simple. Go to the page and allocate a Service Bus namespace. The ‘Hello, World’ for the queue looks like this:

static void Main(string[] args)
  var sbNamespace = "your namespace";
  var credential = TransportClientCredentialBase.
    CreateSharedSecretCredential("owner", "[your key]");
  var uri = ServiceBusEnvironment.CreateServiceUri("https", sbNamespace, 
  var client = new ServiceBusNamespaceClient(uri, credential);
  var messagingFactory =
    sbNamespace, string.Empty), credential);
  var queue = client.CreateQueue("demo");
  var queueClient = messagingFactory.CreateQueueClient(queue);
  var sender = queueClient.CreateSender();
  var receiver = queueClient.CreateReceiver();
  var message = receiver.Receive();

Leave a comment

Integrating with the Camera in WP7

There has been a small white lie that many people tell when looking at whether or not a WP7 application can directly interact with the camera. The fib looks like this:

You can only access the camera through the CaptureCameraTask. Direct access is not allowed.

It didn’t seem right when I heard that, so I did some digging around, looking for ways to find out what is really contained in the phone. Some information is out there, and if you assemble the parts, you wind up with a better view into what managed code can do on the phone. I wrote a post earlier that showed what you need to do in order to make your development environment work better. As a result of that effort, you are going to be able to use the camera in your Windows Phone 7 applications today.

Adding live support for a phone is actually pretty easy. You just need to add some references to the right assemblies, add a little markup to your page, and then write a few lines of code.


Go ahead and create a WP7 XAML app. Once you do that, you need to add references to two assemblies that aren’t standard issue:

* Microsoft.Phone.InteropServices

* Microsoft.Phone.Media.Extended

Why two assemblies? The first one allows you to work with the second one-nothing more.

Add some markup to display the camera

To work with the camera, live, here is what you do:

1. Add a reference to the Microsoft.Phone.Media.Extended to the page you want to display the camera output to. For example, add the following to the PhoneApplicationPage element:


2. With that in place, you can then put a CameraVisualizer on to your page. A CameraVisualizer displays the content of a camera on to a surface.

<media:CameraVisualizer Name="cameraVisualizer" Visibility="Visible" 
    Margin="64,4,99,26" Height="426" Width="593" />

Hook up the Camera to the Page

In your page’s code behind, add a Microsoft.Phone.PhotoCamera and attach it to the CameraVisualizer. You do that by calling SetSource on the visualizer. The code looks like this:



Doing something with the Camera

From there, you can access methods telling you what is going on with the camera:

* ShutterPressed: Fires when someone presses the camera button.

* ImageSavedToDisk: Fires when the image you just took is saved to disk, passing along the path to the file.

* ThumbnailSavedToDisk: Fires when the thumbnail is saved. This one also has the image path.

When the shutter is pressed, you still need to tell the camera to take the picture. To do this, fire the CaptureImage method on the PhotoCamera instance. You can also do some cool things like set the flash setting, zoom level, and auto focus.

There are a few gotchas with the camera that do make it difficult to work with and show why it wasn’t available to all of us when the phone launched. First off, any time you use the control just a little bit ‘incorrectly’, you will see a COM exception. Second, any time that the visualizer goes off screen then back again, you need to detach any events, then hook them back up again or you will have a bad experience for your users. If you do not handle the pictures being taken in quick succession, you will have issues.

I invite you to play with the camera but be warned-it is a nasty beast to work with and you will spend quite a few cycles fixing weird little bugs. Microsoft never made a general release of this code because the code needed more QA before burning any cycles documenting the feature. They’ve already announced it will be in better shape for Mango, but if you want to use it now, I’ve given you enough rope. Have some fun (and don’t hang yourself)!!!

Thanks to Jeff Prosise for encouraging me to talk about this. We were chatting in late April at a conference when I was having some fun with a WP7 camera app I had written and he said he wanted to know how I did that.

Leave a comment

The Windows Azure AppFabric CTP For May has Shipped

The May 2011 AppFabric updates have shipped. You can get them all from here: Coverage is exploding over at TechEd, Clemens Vasters can finally talk about topics, and it’s a grand day. So, many of you will be digging into the source and will want a CHM file that works. The that you download will be blocked from showing Internet content and when you open it, you will see something like this:


If you do see that ‘Navigation to the webpage.’ message, here is what you’ll need to do.

1. Right-click on the CHM file and select ‘properties’.

2. On the General tab, there is a button WAAAAAAYYYYYYY at the bottom labeled Unblock. Click that button so that the content from the Internet will display just fine on your PC.


3. Reopen the CHM and you’ll be able to actually view things.

Leave a comment

Adding the ‘other’ WP7 Libraries to your VS 2010

WARNING: Everything I’m sharing with you is unsupported. You may or may not be able to publish WP7 applications to the Marketplace using these features. The point behind this is to satisfy hackers. This does NOT modify your phone in any way-it just makes it easier to dig into what WP7 already does. If you use these undocumented features, Microsoft may later change these APIs your applications when they choose to document these features or remove them from a future image of your WP7 phone. Microsoft does not promise to keep these APIs alive between WP7 updates. Got it?

I was curious what goodies were on the phone but not available to everyone else. I knew that people had grabbed the OS image and pulled apart the files on it already, so I figured someone had probably hacked that part already. After some searching, I found this: The handy thing here is that Thomas Hounsell also dumped out all the libraries and gave a hint as to how to include these in our own applications. In there, you will find all sorts of goodies. The binaries he provides include EVERYTHING- documented and undocumented. I didn’t see complete details on how to wire up the additional, undocumented bits. Here are my extra instructions:

1. Unpack the binaries from here.

2. Copy the dlls to C:Program Files (x86)Reference AssembliesMicrosoftFrameworkSilverlightv4.0

3. Run the following commands from a VS 2010 command prompt, running as administrator (line breaks are in the right place, so copy and paste from here should work):

move GAC_CustomMarshalers_v3_7_0_0_cneutral_1.dll CustomMarshalers.dll
move GAC_Microsoft.Phone.InteropServices_v7_0_0_0_cneutral_1.dll Microsoft.Phone.InteropServices.dll
move GAC_Microsoft.Phone.Media.Extended_v7_0_0_0_cneutral_1.dll Microsoft.Phone.Media.Extended.dll
move GAC_Microsoft.ServiceModel.Channels.Mail.WindowsMobile_v3_7_0_0_cneutral_1.dll Microsoft.ServiceModel.Channels.Mail.WindowsMobile.dll
move GAC_Microsoft.ServiceModel.Channels.Mail_v3_7_0_0_cneutral_1.dll Microsoft.ServiceModel.Channels.Mail.dll
move GAC_Microsoft.VisualBasic.SR_v8_1_1_0_cneutral_1.dll Microsoft.VisualBasic.SR.dll
move GAC_Microsoft.VisualBasic_v8_1_1_0_cneutral_1.dll Microsoft.VisualBasic.dll
move GAC_System.Data.DataSetExtensions_v3_7_0_0_cneutral_1.dll System.Data.DataSetExtensions.dll
move GAC_System.Data_v3_7_0_0_cneutral_1.dll System.Data.dll
move GAC_System.Messaging_v3_7_0_0_cneutral_1.dll System.Messaging.dll
move GAC_System.Net.IrDA_v3_7_0_0_cneutral_1.dll System.Net.IrDA.dll
move GAC_System.SR_v3_7_0_0_cneutral_1.dll System.SR.dll
move GAC_System.Web.Services_v3_7_0_0_cneutral_1.dll System.Web.Services.dll
move GAC_System.Windows.debug.resources_v2_0_5_0_cen-US_1.dll System.Windows.debug.resources.dll
move GAC_System.Windows.RuntimeHost_v2_0_5_0_cneutral_1.dll System.Windows.RuntimeHost.dll
sn -Vr CustomMarshalers.dll
sn -Vr Microsoft.Phone.Interop.dll
sn -Vr Microsoft.Phone.InteropServices.dll
sn -Vr Microsoft.Phone.Media.Extended.dll
sn -Vr Microsoft.ServiceModel.Channels.Mail.dll
sn -Vr Microsoft.ServiceModel.Channels.Mail.WindowsMobile.dll
sn -Vr Microsoft.VisualBasic.dll
sn -Vr Microsoft.VisualBasic.SR.dll
sn -Vr System.Data.DataSetExtensions.dll
sn -Vr System.Data.dll
sn -Vr System.Messaging.dll
sn -Vr System.Net.IrDA.dll
sn -Vr System.SR.dll
sn -Vr System.Web.Services.dll
sn -Vr System.Windows.RuntimeHost.dll
del GAC_*.dll


4. From that administrative window, use notepad to open up

C:Program Files (x86)Reference AssembliesMicrosoftFrameworkSilverlightv4.0ProfileWindowsPhoneRedistListFrameworkList.xml

5. Within the XML add the following lines before the closing tag in the document (and save the file!):

  <File AssemblyName="Microsoft.Phone.InteropServices" Version="" Culture="neutral" PublicKeyToken="24eec0d8c86cda1e" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="Microsoft.Phone.Media.Extended" Version="" Culture="neutral" PublicKeyToken="24eec0d8c86cda1e" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="CustomMarshalers" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="System.Data" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="Microsoft.ServiceModel.Channels.Mail.WindowsMobile" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="Microsoft.ServiceModel.Channels.Mail" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="Microsoft.VisualBasic" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="Microsoft.VisualBasic.SR" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="System.Data.DataSetExtensions" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="System.Data" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="System.Messaging" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="System.Net.IrDA" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="System.SR" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="System.Web.Services" Version="" Culture="neutral" PublicKeyToken="969db8053d3322ac" ProcessorArchitecture="MSIL" InGac="false" />
   <File AssemblyName="System.Windows.RuntimeHost" Version="" Culture="neutral" PublicKeyToken="31bf3856ad364e35" ProcessorArchitecture="MSIL" InGac="false" />

And that’s pretty much all you need to do in order to get access to the other DLLs within VS 2010.

Leave a comment

Rumors of WPF's Death are Greatly Exaggerated

It seems that, over the last several months, people have become convinced that WPF is dead. Having seen the pace of change in previous desktop UX technologies, I think this concern is unfounded. Has the talk about WPF declined since it launched? Of course. Adoption is no longer a concern. Anyone who needs a desktop application knows WPF exists, books and training are available, and the knowledge is out there. Microsoft doesn’t really need to work hard here at this point in time. So, why the angst around WPF?

It seems that the fundamental concern is around the fact that many vendors have stopped fighting for the desktop and have resumed the fight at the browser, saying my HTML5 is better than theirs. The desktop war has gone quiet again and Microsoft still owns that platform, so they’ve visibly shifted investment from the desktop to where the battle is: in browsers and HTML5. That doesn’t mean that they’ve stopped building WPF, or WinForms, or WebForms, or MFC. But, Microsoft has visibly reduced its investment in those areas. The current set of big bets has been expensive: Azure, WP7, XBox, and Bing. A large part of the Azure investment involves moving server platforms to the cloud. That investment is particularly expensive because now everything has to work on premises and in Azure. Microsoft has limited resources and trying to get significantly more desktop functionality in the next several years just doesn’t make sense from a fiduciary point of view. The WPF team still lives, it’s just smaller than in 2005.

To appreciate the pace of innovation in WPF, take a look at this ScottGu post from 2009:  I expect a similar amount of forward momentum in .NET 5 to add Windows 8 features for WPF developers. WPF is now a mature, stable, technology. Like other libraries in .NET, innovation is no longer around building the perfect class library but instead on enhancing the library’s usability and utility. The same things are happening in WCF, System.Transactions, System.Net, System.Security, and other namespaces that we never hear about but that we know haven’t been abandoned.

As .NET developers, we need to articulate these facts to project sponsors. When they say “I hear WPF is dead” have them look at WPF and how it has grown. Look at what it does. Explain that the investment in WPF has declined because the amount of work to get done today is incremental– support video cards better, add support to match Windows Shell innovation, improve drawing. The library is still being enhanced. tells the story of what people want and what is being accepted into the next version of WPF.

If that’s not enough, remind the naysayer that even MFC is still being enhanced.

Leave a comment

Houston TechFest 2010: Code and Samples from my WCF/RIA Talk

I had a great time talking to the folks at the Houston TechFest. Much thanks also to Addison-Wesley for sponsoring my trip to Houston. If you are interested in becoming an technical author, let me know and I can put you in contact with the editors at Addison-Wesley (

As promised, my slides and code are online:

Let me know if you have any questions about the code, the presentation, or life as an author.

Leave a comment

Clean paths with WCF Hosted Workflows

I am a big fan of the things added to WCF 4.0. One of those things is the deep integration with ASP.NET routes. Today, I was writing a service in WF and hosting the workflow with WCF. I really didn’t like the service URL-yeah, I’m a picky developer who doesn’t like exposing implementation details in the URL.

I knew a few things:

1. WF/WCF integration provides a ServiceHostFactory named WorkflowServiceHostFactory for hosting XAMLX files in WCF.

2. WorfklowServiceHostFactory will see CreateServiceHost called with some constructorString plus a bunch of baseAddresses.

3. I wanted the host to work on HTTP only-I don’t care about goofy URLs for net.tcp.

4. XAMLX services do not have a runtime defined type- they exist only in XAML.

My goal was to create a new route type, like ServiceRoute, that allowed me to pass in the desired path and the path to the XAMLX to instantiate. After a few minutes of thinking and hacking, I had the following:


public class WorkflowServiceRoute : ServiceRoute
  public class HostedWorkflowServiceHostFactory : 
    public HostedWorkflowServiceHostFactory(string xamlxPath)
      XamlxPath = xamlxPath;

    string XamlxPath { get; set; }

    public override System.ServiceModel.ServiceHostBase CreateServiceHost(
      string constructorString, Uri[] baseAddresses)
      return base.CreateServiceHost(XamlxPath, baseAddresses);

  public WorkflowServiceRoute(string routePrefix, string xamlxPath)
    : base(routePrefix, 
           new HostedWorkflowServiceHostFactory(xamlxPath), 

I’m pretty happy with the succinctness of the class and the fact that it works on the few use cases I have at hand. Requests are directed to the correct locations and integration seems to be just fine. Use of the WorkflowServiceRoute is just:

routes.Add(new WorkflowServiceRoute("helloWorld", "SimpleWorkflow.xamlx"));

Frankly, this is the first implementation I thought to write, and it works. The code size is small. I don’t like a few things about it, but I’ll live. Things I don’t like:

1. Passing typeof(object) to the base constructor from the route seems wrong. The receiver code thinks it needs a reference to the service type at all times. I’m just lying to the ServiceRoute so that I can take advantage of everything good about it.

2. Custom ServiceHost just so the code can remember the path to the XAMLX. This bothers me until I think that this is the same thing that happens with each .SVC or other XAMLX file.


As a benefit, I get URLs that look like this:

instead of:


This serves as yet another example of how good it is that WCF is super extensible and what a great design decision it was to build WCF on top of the extensibility points instead of along side them.

Leave a comment

How JSONP works (and some bits about implementing it in WCF)

In the world of the web, we have lots of security concerns. One of the concerns lies with cross site scripting, XSS. From a high level, XSS is any occasion where data is sent from code on a page from one site to another site. The code is usually via JavaScript, though flash and Silverlight are included in the terminology and mitigations. One way around this that is generally viewed as safe is JSON with Padding, aka JSONP. The way JSONP works is this: you pass an HTTP GET request to retrieve a resource from another site which you do not control. The request contains two pieces of information:

1. The resource you want to retrieve.

2. The callback function that should be executed when the resource is returned.

What makes this safe? The callback function is always something that you control. It is assumed that if your callback does bad things, so be it; that problem existed without involving JSONP.

There is a convention around JSONP. The URL that you call needs to understand a querystring parameter named callback, which identifies the function to call when the method returns. How does this work? Assume we have a resource that, when no callback is specified, returns the following when requesting the resource at





With JSONP, we would like a GET of the above data to execute a function on our page named updatePeople. JSONP indicates that we do this with a request for the resource at http://localhost/WcfJsonp/jsonp/names?callback=updatePeople. In so doing, the resource is now returned as:





This causes the function, updatePeople, to be called as soon as the resource is retrieved.

How does this work? Most of us will use jQuery to get the job done and not think about things. But, without jQuery, JSONP is still possible. I’ll first show you how this works by hand, then with jQuery. jQuery eliminates a number of potential bugs, so I recommend reading the by hand portion solely to understand things-don’t implement it in production code!

Assume you have the following HTML body:


      <input type="button" onclick="getPeopleJsonp();" 
             value="Get people" />
    <div id="people"></div>
    <script type="text/javascript" 
    <script type="text/javascript">
        function updatePeople(data) {
          var innerHtml = "";
          for (i = 0; i < data.length; ++i) {
            innerHtml += data[i].FirstName + ' ' + 
                         data[i].LastName + '<br/>';

        function getPeopleJsonp() {
          var innerHtml = "<script type='text/javascript' " + 
                          "src='http://scottseely-xps/wcfjsonp/" +
    <div id="inject"></div>

What is happening here? When someone clicks on the button, the page calls getPeopleJsonp. That code updates the content of the div whose id is inject to contain a script tag. The script tag points to a JSONP endpoint and passes the callback parameter indicating to call the function updatePeople upon success. That script is then evaluated, executes a local JavaScript function, and returns. Every time that same script is reinjected, the same behavior occurs.

Now, jQuery provides a more succinct mechanism for doing the same thing. Instead of having the previous two functions and updating the DOM ourselves, we would write this:


function getPeopleJquery() {
    dataType: 'jsonp',
    url: "http://scottseely-xps/WcfJsonp/jsonp/names",
    success: function (data) {
      var innerHtml = "";
      for (i = 0; i < data.length; ++i) {
        innerHtml += data[i].FirstName + ' ' + data[i].LastName + '<br/>';

The code to inject information into the DOM still occurs, as does the creation of a callback function. What jQuery does is it adds script tag to the DOM only until the callback (success function) is done executing. The tag is added to the header. It also adds a function to the window object which is called on return. The URL jQuery constructs looks like http://localhost/WcfJsonp/jsonp/names?callback=jsonp1283609644773. What it actually does is add the following:


Within the window object, a new function is added:


jsonp1283609644773 is just an object living on the window object and is a dynamically added function. When the function is done executing, it will remove itself from the window object, leaving a slot by the same name with a value of undefined. What does the function look like when it is alive?

function(q){n=q;b();d();z[i]=v;try{delete z[i]}catch(p){}A&&A.removeChild(B)}

So, yeah, not too intelligible, but it does appear to handle things just fine. b(), d(), and the other functions are all part of the minified jQuery library, meaning that it all makes sense in the context of the containing object. The call to b() is contains code to call the success function. Everything else is cleanup code (at least from what it looked like to me.). To make this whole thing work in WCF, you need to do a couple simple things:

1. Only use WebGet to fetch resources.

2. Make sure the resource is hard-coded to respond in JSON. Otherwise, the response will appear as XML and the callback code won’t execute.

3. Make sure your binding supports JSONP.

4. Make sure your service requires ASP.NET compatibility.

For example, to get the names, I have the following WCF code:

  RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class JsonpDemo
  [WebGet(UriTemplate = "names", ResponseFormat = WebMessageFormat.Json)]
  public PersonName[] GetNames()
    return new PersonName[]
                new PersonName {FirstName = "Scott", LastName = "Seely"},
                new PersonName {FirstName = "Aaron", LastName = "Skonnard"},
                new PersonName {FirstName = "Matt", LastName = "Milner"}

Configuration has:

  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
      <standardEndpoint crossDomainScriptAccessEnabled="true"


The crossDomainScriptAccessEnabled flag turns on the ability to correctly parse and respond to the presence of the callback parameter in the query string.

Finally, I added a route to handle the service within my Global.asax:

var factory = new WebServiceHostFactory();
routes.Add(new ServiceRoute("jsonp", factory, typeof(JsonpDemo)));

I was looking at the technology only to evaluate how to use it and to understand, a bit more deeply, how JSONP actually works. I found myself looking for a post that explains the magic, but most of the information I found just said “use jQuery.” Handy-sure. But that didn’t help me understand all the magic goodness that jQuery was doing for me.

Leave a comment