Friday, August 15, 2008

WCF 101 Screencast

Cliff, our stud WCF product manager, just posted a Channel9 video where Aaron goes through the process of creating a WCF service from scratch.  The video is nice in that it isn't just a typical "let's race to do something really simple in under a minute", but actually goes through setting up contracts, configuring the service with an endpoint using the config tool, and hitting it with the test client.  Good introduction for someone who's familiar with .NET but has never written a WCF service.

BTW, the Pluralsight guys have created another shirt I have fun wearing... the first one being the one with the caption /{real}/{webservices}/{use}/{uris} :-)

Rumor has it that Jon was responsible for creating and sending a box of them over... thanks!  (and of course to Matt/Moustafa for delivering...)


 | 
Friday, August 15, 2008 5:51:57 AM (GMT Standard Time, UTC+00:00)  #  Comments [2] 

Time to Outsource my Blog :-)

I run my own blog server from home.  It affords a nice degree of flexibility in that I can really control the software I put on there, and customize it for my purposes.  For example, I was able to mess around with the dasblog code, and add WCF-based endpoints for RSS/Atom, as well as create my own support for logging in and leaving comments with CardSpace.

There are some big downsides too though.  One is that I have to maintain my own software on the blog server.  Back in July 07 I decided to repurpose an old 4-proc machine I had as my blog server, and installed Windows Server 2008 RC1.  That proved to be a rock solid OS and I got to play around with WS08, which was fun... but a few days ago, I discovered that I couldn't mstsc into the machine anymore, so I tried to log in manually, and found out that my RC1 license key expired.  Doh! 

I tried to put in an RTM license key, but that wasn't recognized as valid (I guess that makes sense).  The OS was nice enough to let me do a "limited login", which means get a browser window that opens up to the licensing site, where you can get a valid license key.  But we already established that an RTM license key wasn't going to fix the problem, so I needed to figure out how to upgrade the software.  Fortunately, I could do anything from that browser window, including typing "c:\windows\system32\cmd.exe" :-)  from there I was off to the races.  Back up all the data on the machine (took a couple of tries, because the machine seemed to time out every once in a while and kick me off). 

Then I had to round up a copy of WS08 Enterprise RTM (thanks Jason!) and tried to upgrade the OS.  Again, took a couple of tries, but at the very very end, somehow the upgrade process failed (argh) and I realized I had to do a fresh install.  Oh well, I backed up all the data, what could go wrong?

Well, everything works fine, I install the app server and webserver roles, get it all working, set up the default web site correctly, create a new application for dasblog... try to hit the webserver from outside, no dice.  Ping works, HTTP.  Did the IP address change somehow?  No.  Are all the NT ACL's set up right?  Yes.  Hmm.  I go to the router to see whether it's still configured to forward traffic to the right server... oh, that's the problem - I forgot to configure the machine with a static IP address.  OK, now HTTP works - yay!

Next let's get HTTPS working.  Darn, forgot to export that certificate!  I knew I'd forget to back something up.  Since my root address is https://www.gazitt.com/blog, all my links are now broken (including all <img> tags).  So now I have to re-request a cert from eNom, and that takes a day.  Net - the site is basically impaired for a good 24 hours.  (Note to self - export cert tonight! :-)

Moral of the story: running my own blog server is probably not worth the hassle... now I need to figure out which server I want to use :-)  asp.net?  MSDN?  PluralSight like all the cool kids?  I'll definitely need to figure that out before the PDC :-)



Friday, August 15, 2008 5:31:59 AM (GMT Standard Time, UTC+00:00)  #  Comments [0] 
 Monday, August 11, 2008

Visual Studio 2008 and .NET Framework 3.5 SP1 RTM Today!

Today, we’re proud to announce the availability of the “gold” bits of VS 2008 SP1 and .NET 3.5 SP1.  We think this is a great update to our VS2008 and 3.5 releases that is well worth checking out. 

I blogged about the new features for Service developers back in May when we shipped the beta, so I won’t repeat them all here… but here is a recap of some of the highlights:

On the Web front, we’ve built on the support for REST and AtomPub with enhancements to UriTemplate and support for AtomPub ServiceDocuments, respectively.  And of course we’ve built Data Services (also known as “Astoria”) – a WCF service that exposes any SQL database (or LINQ provider) as a set of AtomPub resources.  Finally, we’ve enhanced our support for partial trust scenarios with the ability to write to the event log, which helps debugging and diagnosability. 

The DataContractSerializer has some nice enhancements, including support for “POCO” (plain-old C# objects) contracts, which allows using this serializer without requiring you to decorate members [DataMember].  This is more than just a convenience – sometimes you don’t control the class you are trying to serialize (for example, it gets generated by a tool which doesn’t slap on the [DataMember] attribute), and this feature now makes it possible to use the DataContractSerializer with those types.  We also added support for serializing object graphs in a way that is more interoperable with JAX-WS, and support for ADO.NET Entity Framework types in DataContracts. 

There’s also some good perf work in this release.  If you’re running in IIS7 integrated mode, we’ve seen 5-10X scalability increases for WCF services via a new asynchronous implementation of our HttpHandler/Module (more details on Wenlong's blog).  Also, the Workflow designer can handle significantly bigger workflows and loads up much faster.

Finally, we have some nice improvements in our tools.  Our Test Client now runs standalone (in addition to running inside Visual Studio).  We also added support for a bunch of new types including Nullable types, Dictionaries, MessageContracts, and XmlSerializer contracts.  The tool also supports WS-RM sessions and allows you to customize the config file for the tool itself, so you can save some common customizations instead of having to recreate them.

The support for XmlSerializer-style contracts opens up some interesting new scenarios for the tool… My favorite is pointing it at a public web service to discover its contract, and use the tool kind of like a browser – i.e. be able to invoke a service with the right parameters and look at its output.  You can find the standalone version of the tool in <Program Files>\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe.  Here’s an example of pointing the tool to the Amazon AWS WSDL and invoking the ListSearch operation to retrieve a WishList for John Doe:

We also added a new publishing wizard for WCF Service projects to facilitate easy deployment of WCF services, loosely modeled on the notion of publishing ASP.NET websites to IIS.  Notice that the WCF Service Library template creates a project that has an app.config – when you hit F5, we spin up our Test Host (think of it like “Cassini for WCF services”), and bring up the Test Client mentioned above.  So the publishing wizard takes a location to publish to, and converts the service from a “self-hosted” service to a Web-hosted service, including taking all the <serviceModel> config information and inserting it into a web.config file.  Here’s a screenshot:

Last but not least, thanks to everyone who tried out the beta and gave us feedback – your efforts help us create a better product and are much appreciated.  Enjoy!


 |  | 
Monday, August 11, 2008 7:46:17 PM (GMT Standard Time, UTC+00:00)  #  Comments [0] 
 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]