Monday, May 12, 2008

VS2008 and .NET 3.5 SP1 Enhancements for Service Developers

Today we released the betas for VS2008 sp1 and .NET 3.5 sp1. Scott did a good job (as usual :-)) running through the top-level enhancements, so I won't parrot it all here.. but I'd like to go through the next level of detail on what new goodies we have for service developers.

The most interesting/exciting feature for service developers is what we call Data Services (previously known as "Astoria").  The best way to explain how Data Services fits into the overall "services platform" that .NET provides is through a picture:

As a service developer, .NET offers me a layered stack - if I want to write "to the metal", I can build a service on top of System.Net and HttpListener (which is a managed wrapper on top of HTTP.SYS - our kernel HTTP driver).  Not many people end up doing that, because there are lots of good pieces that we've already written for you..

WCF provides the next layer.  WCF gives you some modular pieces, such as channels (HTTP, TCP, MSMQ, etc); Serialization, which is a fancy word for pouring objects into a serialized formats such as XML, binary, JSON, and deserializing back into objects; and what we call "Syndication", which are some classes that support various data publishing microformats such as RSS and ATOM.  Finally, we have a layer called Service Model that ties all of this stuff together in a coherent, approachable programming model. 

WCF is a powerful but general framework, so the next layer up consists of particular scenarios that we wanted to significantly simplify. I think of two canonical scenarios for writing services: "resource-oriented" services, where you model your service as a bunch of resources and offer request/response, HTTP-based access to those resources; and "operation-oriented" services, where you want to create a new "operation" that wraps a more involved operation that often has to coordinate state changes across multiple resources.

Operation-oriented services become more attractive the more asynchrony you need in your service implementation.. the canonical example is "book a trip" which in turn composes other asynchronous services, such as "book the airfare", "book the hotel", etc.  We realized that most operation-oriented services are actually most easily modeled as workflows.. and that's why we invested heavily in .NET 3.5 in Workflow Services, which is a pretty deep integration between WCF and Workflow.

Resource-oriented services became easier to write in .NET 3.5 via our REST support that we added to WCF.  But we thought we could do even better for some canonical scenarios, such as when you have data in a database (or any LINQ data source) that you want to expose over REST/ATOM.  So the ADO.NET team built Data Services, which is layered on top of WCF's REST and ATOM capabilities and offers a really easy way of doing just that. 

Any layer of abstraction makes some choices, and some of those choices may not be exactly what you want.  The nice thing is that given the layering of Workflow Services and Data Services over WCF, if you don't like the choices we've made for you, you can always drop down to the layer below (WCF). 

As I type this, I realize that there's really one additional scenario that I didn't capture in the picture - which is "services that back a presentation layer".  ASP.NET AJAX is the obvious example of that today.. in .NET 3.5, we added support for being able to "back" an ASP.NET AJAX page with a "AJAX-Enabled WCF Service" (complete with a VS template).  So that's another example of a targetted scenario that's layered on top of WCF... (I'll have to fix my picture :-))

Besides Data Services, there are some additional cool new enhancements in WCF and WF that are worth mentioning:

  • We are enabling DataContract Serializer to serialize types without the need to annotate them with the [DataContract] attribute and its relatives.  We affectionately have taken to calling this feature POCO (plain old C# Objects), tipping our hat to POJO :-)
  • We’ve enabled interoperable object references in our serialization format.  This was done to support certain Entity Data Model (EDM) types but is generally useful in improving our interoperability with Java
  • We’ve made the WCF Test Client (the form that comes up when you hit "F5" on a service) into a stand-alone tool and added more features to increase the breadth of web services it can handle
  • The WCF Service template is now available in the Visual Web Developer Express SKU
  • We are delivering a hosting wizard for Visual Studio WCF Service projects that allows easy deployment of Web Services from VS into IIS
  • Event Logging is now enabled in Partial trust so that people who host their services in medium trust environments have more of the WCF "juice" :-)
  • We extended the syndication OM to support the ServiceDocument in AtomPub
  • We did some nice perf enhancements to the WF activities designer to make it much more snappy, even if you have a large number of activities

And of course, we fixed many of the most common bugs that you all have reported to us (thanks!)

All in all, a bunch of good value in a service pack release.. of course, this is a beta, so there are still some issues in the bits.  Please give them a test-drive and let us know what you think!

 


 |  | 
Monday, May 12, 2008 5:47:49 PM (GMT Standard Time, UTC+00:00)  #  Comments [2] 
 Monday, March 17, 2008

Deploying a Silverlight2 Beta1 Web Project to IIS

SL2 beta1 adds a new packaging format for Silverlight apps - a .xap file.  Silverlight apps work fine in cassini (the ASP.NET development webserver), but trying to deploy the web project to IIS results in a blank page where the silverlight control ought to be.

The issue is that IIS needs to be told about the mapping between the extension and the MIME type.  To fix it, open the IIS MMC, open the MIME Types editor, and add a new entry with the file name extension ".xap" and the MIME Type being "application/x-silverlight-2-b1".  Refresh your page and that should do it...



Monday, March 17, 2008 12:24:19 AM (GMT Standard Time, UTC+00:00)  #  Comments [0] 
 Sunday, March 16, 2008

Migrating from the VS2008 Beta2 LINQ-to-SQL to RTM

While I'm on migration, here are some pointers for stuff I had to do when migrating my LINQ-to-SQL project from VS2008 Beta2 to RTM.

  • The DBML file was unreadable because the Beta2 version had an encoding="utf-16" attribute on the <?xml> decl, but the file itself didn't have an Unicode BOM.  Changing this to utf-8 fixed that problem.
  • .Remove() has been renamed (probably more aptly) to .DeleteOnSubmit(). 

That's pretty much all I had to do to port my LINQ-to-SQL project to VS2008 RTM..



Sunday, March 16, 2008 12:08:25 AM (GMT Standard Time, UTC+00:00)  #  Comments [0] 
 Saturday, March 15, 2008

Migrating from Silverlight 1.1 Alpha to Silverlight 2 Beta1 Projects

I got some time this weekend to start migrating my SL1.1 alpha app to SL2 beta1.  For starters, the SL 1.1 alpha project file contains reference (<import>) to a project file that doesn't exist anymore - you get the following error when trying to load the project:

"Unable to read the project file '... .csproj'. ... The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\Silverlight\Microsoft.Silverlight.Csharp.targets" was not found."

I started hunting for the right <import>, and then came upon this blog entry that provides all (well, most) of what you need to know for migration...

After changing the project <import> from ...\VisualStudio\v9.0\Silverlight\... to ...\Silverlight\v2.0\..., I was able to read the project file.  After that, I removed all references to all assemblies, and re-added references to mscorlib, system, System.Core, System.Windows, System.Windows.Browser, System.Windows.Controls, and System.Xml, and I got my 576 errors reduced down to 15.  Not tooo shabby! :-)

There were a few more "simple and mechanical" changes to make the project compile:

  • Some EventHandler's had to be changed to MouseEventHandler, some MouseEventHandler's had to be changed to MouseButtonEventHandler
  • System.Windows.Media.Visual is gone - I was able to use System.Windows.UIElement for the same purpose (a generic type for all types of silverlight controls)
  • KeyboardEventArgs --> KeyEventArgs
  • System.Windows.Browser.Net is gone - BrowserHttpWebRequest is not needed anymore.  You can now use the System.Net assembly and use HttpWebRequest.Create().
  • The old System.Web.Services namespace (which was the ASMX client) has now been replaced by the WCF client (woohoo!)  So you have to remove your old Web Reference and add a new Service Reference.

Those were the key changes I made to make the project compile. 

Update: a couple of things I forgot to note (turns out I had more than one Silverlight project :-))

  • A few more type changes: some EventHander's --> RoutedEventHandler's
  • No synchronous proxies from Add Service Reference: need to convert to the async equivalents
  • Change all of the generic forms of X.SetValue<type>() to the non-generic versions - X.SetValue()
  • HtmlPage.Navigate() doesn't exist - use HtmlPage.Window.Navigate()
  • XamlReader is now in System.Windows.Markup (have to add the using directive)
  • System.Windows.Input.Cursors.Default no longer exists
  • System.Windows.Controls.Image.Source is now a bit more involved - now ImageSource is an abstract class that's more than just a Uri.  The most convenient concrete class is BitmapImage (defined in System.Windows.Media.Imaging), which has a UriSource property that's typed as a Uri.  So instead of

    Image.Source = new Uri("http://foo", UriKind.RelativeOrAbsolute);

    Image.Source = new BitmapImage(new Uri(http://foo, UriKind.RelativeOrAbsolute));

  • Point[] --> PointCollection
  • HtmlDocument.Document.GetElementByID --> HtmlDocument.Document.GetElementById


Saturday, March 15, 2008 11:34:09 PM (GMT Standard Time, UTC+00:00)  #  Comments [0] 
 Wednesday, February 06, 2008

MySpace API's

The MySpace developer API's launched today.  Their API's are all RESTful, and they built them using WCF's REST features that we just shipped in .NET 3.5.  MySpace will be talking about their experience at MIX08, so if you're going, you should check out the talk..

 


 | 
Wednesday, February 06, 2008 7:05:52 AM (GMT Standard Time, UTC+00:00)  #  Comments [0] 
 Thursday, January 24, 2008

IIS7 and Certs

Can SSL configuration be more arcane?  A week ago I noticed that my Server cert expired.  I bought a new SBS cert via eNom (my domain name provider).  SBS posts easy enough directions on their website for installing the cert.  Four days later, I finally have it working.

Basically, a three step process. 

  1. Step one is you create a new certificate request in the IIS MMC; take the base64-encoded request, submit it into a form (or send it via e-mail), get it validated by the SBS folks, who send you back a base64-encoded certificate, along with some trusted root and intermediate authority certificates. 
  2. Step two is using the cert management MMC plug-in to install the trusted root and intermediate certs (always a pleasure using that tool I tell you). 
  3. Step three is completing the certificate request in IIS by supplying the base64-encoded cert file and IIS creating the appropriate corresponding private key file.

First mistake: remove the old (expired) cert before I have the new one working.  Oops.  No HTTPS support for my site until I fix it.

Second mistake: forgot to install the trusted root cert before completing the IIS process.  Once you complete the process, no going back.  Need to create a new request, send it to SBS, and get a new cert.  One more day lost.

Now comes the hard part.  New server cert installed, all the right supporting certs are in place, but IIS fails every HTTPS request (no error logs).  The page IE displays is just like a DNS lookup failure, but it comes back immediately (as opposed to looking for latency you see with DNS failures).   So what's going on?  netstat -a shows that port 443 is in LISTENING state.  telnet localhost 443 confirms (but resets the connection with the first keystroke).  Firewall seems to be fine (allows 443).  Time to sleep on it.

Now it's time to find a new machine and try to put the cert on it "from scratch" to see if the issue is the old machine.  As soon as I go in to add HTTPS to the site's bindings, the problem becomes apparent: the HTTPS protocol requires a cert to be associated with it... bingo!  The issue is that the old cert is gone, and I haven't re-associated the HTTPS binding with the new cert.  You'd think that the site would just come back with a "bad cert" error message but it just got stuck in a very hard to diagnose state.

Now comes the fun part.  When I try to remove the HTTPS binding and recreate it using the new server cert, I keep getting a dialog with a weird error message ("A specified login session does not exist. It may already have been terminated").  That's a logon error which seems to indicate some bad permissions.  Sure enough, other certs that I have lying around on the machine work.  So how do I fix this one?  SIMPLE.  Just set the right permissions on the private key file.  What could be easier?

  1. find the SHA1 thumbprint of the cert.  You can do that easy enough inside IIS
  2. find the "findprivatekey.exe" utility (we snuck it into the WCF SDK a while back, so I have it lying around on one of my machines, but it's also on MSDN)
  3. use that utility to find the private key file associated with the thumbprint (findprivatekey my localmachine -t <thumbprint> -a).  That returns a file in the MachineKeys directory.
  4. bring up the file in explorer
  5. set the right permissions (or use the cacls utility) - give NETWORK SERVICE read access.  Ah, that doesn't quite work.  Heck, just give Everyone access.  That does the trick - yay!

Someone remind me - why do I still run my own website??

 


 | 
Thursday, January 24, 2008 7:06:56 AM (GMT Standard Time, UTC+00:00)  #  Comments [2] 
 Tuesday, November 13, 2007

iPhone

Just got an iPhone.  Yes, it's all that.  Amazing little device. 

My HTC "startrek" (aka cingular 3125) died a bizarre death (even reloading the ROM image of Win Mobile 5 didnt' help - must be some hardware issue).  So this was the perfect opportunity to get me one of those little toys.

It's hands down a better phone than any smartphone I've had before.  The UI is intuitive, elegant, and chic.  Most importantly, the web browsing experience is actually functional (the first time I've ever felt that about a phone).

Of course, the biggest limitation is lack of ActiveSync support.  This has been the single most useful feature of my smartphone - the ability to sync calendar and e-mail items over the air (and using "push" as opposed to having to manually or even automatically pull).  There have been rumors for months about Apple licensing ActiveSync and delivering this functionality, but it hasn't happened yet.  I bought mine hoping that it'll happen around the time Apple opens up the phone for developers (Feb 08).

 



Tuesday, November 13, 2007 7:50:21 AM (GMT Standard Time, UTC+00:00)  #  Comments [0] 
 Thursday, July 26, 2007

Moved OhmBlog to Windows Server 2008 bld6001 / IIS7

So far, it's been surprisingly easy to migrate my webserver and blog to IIS7 (from which this blog entry is being served).  I basically xcopied my inetpub/wwwroot directory and granted r/w access to NETWORK SERVICE.  The "tricky" part I was dreading was cert management - but it was amazingly easy; I basically copied the certificates I got from SBS over to the new machine, double-clicked on them (which put them in the "default" places), then exported my IIS cert on the old machine and imported on the new machine.  Had my linksys redirect HTTP and HTTPS traffic to the new machine.  All done.

So far I've fully tested the http/https paths to the main page (boy, that's old, I need to put something new there :-)); the blog; and the web services (both the ASMX and the WCF versions).  I'm not 100% sure I have CardSpace working yet - will test tomorrow...

I like the new IIS admin UI but it does take some getting used to.  Fortunately I've played around with it enough on my Vista boxes to get the hang of it, but for people who are used to the old MMC interface, I can imagine it may be a bit frustrating at first (it was for me).  But overall, a much cleaner interface that does simplify many things that were difficult/unintuitive (e.g. cert management).

 



Thursday, July 26, 2007 6:14:11 AM (GMT Standard Time, UTC+00:00)  #  Comments [0]