Reaching a More Permanent Conclusion
Taking some mandatory time off for system maintenance and upgrading grew into deciding that the time was right to make the arrangement more permanent. That was probably apparent a few weeks ago but officially now the 1,111th post here is also the last one.
I’m done but there’s still plenty more to say about WCF. For continued news and updates at least try the Endpoint blog by Ron Jacobs. Regularly delivered technical content is a little harder to find but I hope that someone on the team is able to take on that opportunity in the future. In the meantime you do have more than a thousand articles to read if you haven’t already.
Extended Down Time
MSDN will be migrating to a new blog platform during all of next week. During that time comments will be disabled, posts will be in the process of migration, and new theme and profile systems will be switched in. I’m planning to hold off trying to post on the normal schedule to avoid having to deal with the pain of migration. That means no posts for at least the next week until everything is back to normal. The entire archive should remain available during this time.
Identity Framework SDK and Training Kit for Visual Studio 2010
A new version of the Windows Identity Framework SDK and developer training kit is available targeting Visual Studio 2010 and .Net 4. The Windows Identity Framework SDK includes samples and Visual Studio templates while the training kit includes hands-on labs and training resources.
The SDK and training kit each have a download option for .Net 3.5 and a download option for .Net 4. It looks like installing both versions of either the SDK or training kit does not work particularly well. The .Net 3.5 option is for use with Visual Studio 2008. The .Net 4 option is for use with Visual Studio 2010. Pick the option matching the framework and Visual Studio version you’ll be using. One exception is that the .Net 4 training kit includes Windows Azure resources targeted at .Net 3.5.
Debugging a Missing HostedTransportConfiguration Type
When browsing to a service hosted in IIS I get an error that the protocol does not have an implementation of HostedTransportConfiguration type registered. What can cause this?
Two things to look at are the IIS site bindings and the installed activation services. All of these examples use net.tcp with default settings but you can substitute in other protocols and options similarly following the same checklist.
First, a configuration for the protocol scheme needs to be associated with the web site. This is normally done when the web site is first set up, but you can add additional site bindings from the command line using the appcmd utility.
appcmd set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']
Second, the site binding for the web site needs to be enabled on the particular application that is to be activated. Again, this is usually done when the web site is first set up but can be changed using the appcmd utility.
appcmd set app "Default Web Site/myapp" /enabledProtocols:net.tcp
Finally, the service that hosts the protocol handler needs to be installed and running. You can check the status of the activation service using the sc utility.
sc query nettcpactivator
If the service is not present or is stopped, then that likely means that the Windows component (for client versions of Windows) or the server role and features (for server versions of Windows) are not enabled. The pkgmgr utility can be used to update the component setup.
pkgmgr /iu: WCF-NonHTTP-Activation
WCF Data Services V1 Client Library and Update
The WCF Data Services team has released the source code for their OData client libraries on .Net 3.5 SP1 and Silverlight 3. This may be of benefit to anyone trying to write their own library for the OData protocol. OData is a protocol for querying and updating data stored using a particular class of data models. The source code is released under the Apache 2 license.
Also recently they’ve put out an update to ADO.NET Data Services for Windows 7 and Windows Server 2008 R2. Data Services are REST-based web services that expose a data model that can be consumed by web clients. Data Services use URIs to address data from a storage system and supports a variety of formats for representing that data, such as JSON or ATOM. This update addresses the issues listed in KB article 982307.
Claims Visualization
Dominick Baier has a visualization for claims in the Visual Studio debugger. I’m not sure what other details to provide. It takes an identity and description for a claim and describes the issuer, metadata, and properties that make up the claim.
Service Activation without Files
WCF services in IIS use a .svc file to bootstrap the process of activating a service. It’s possible but not recommended to put the entire service source code and definition in a .svc file to be dynamically compiled and run. Instead, the information that’s typically conveyed is:
- The identity of the service being instantiated
- The base address at which the service exists within the address space of the overall web site
- The service host factory type that will be used to construct the service host
Based on the provided information, the service host factory is created, the service definition is loaded, and the service starts listening on the base address.
In .Net 4 it’s possible to define services through application or machine configuration as an alternative to creating a .svc file. The configuration includes the same information the .svc file would.
Service activation configuration is a new configuration element within the ServiceHostingEnvironment configuration section. The service activation configuration is a collection of service definitions that specify for each service:
- The identity of the service being instantiated
- The relative address at which you would have put the service file before
- The service host factory type that will be used to construct the service host
The relative address functions exactly as if a file exists at the specified location. Based on the path of the relative address, requests will be passed to the service. Based on the extension of the relative address, a build provider will be invoked to construct the service. The only difference from before is that you don’t have to actually create or deploy the separate service files. Service files are virtualized from the information provided in the configuration.
Routing and Impersonation
Can the routing service introduced with .Net 4 be used with impersonation?
Yes, the routing service can be used with impersonation for both sending and receiving messages. All of the usual Windows constraints of impersonation apply. If you would have needed to set up service or account permissions to use impersonation when writing your own service, then you’ll have to do those same steps to use impersonation with the routing service. The WCF configuration for impersonation is simplified though.
Impersonation with the routing service requires either the use of ASP.NET impersonation while in ASP.NET compatibility mode or the use of Windows credentials that have been configured to allow impersonation.
The only step to use ASP.NET impersonation with the routing service is to enable ASP.NET compatibility mode on the service hosting environment. The routing service has already been marked as allowing ASP.NET compatibility mode and impersonation will automatically be enabled. Impersonation is the only supported use of ASP.NET integration with the routing service.
To use Windows credential impersonation with the routing service you need to configure both the credentials and the service. The client credentials object that you use has an allowed impersonation level that must be set to permit impersonation. Finally, on the service you need to configure the ServiceAuthorization behavior to set ImpersonateCallerForAllOperations to true. The routing service uses this flag to decide whether to create the clients for forwarding messages with impersonation enabled.
Multiple Site Bindings
A WCF application in IIS is a service page that is hosted under a site. You can assign different bindings to the site that describe the protocols through which the site can communicate. It’s possible to assign multiple protocols to a single site by specifying bindings that have different protocol schemes. It’s also possible to assign multiple addresses for a single protocol to a single site by specifying bindings that have the same protocol scheme.
WCF has supported services hosted in IIS that have multiple protocols but not services that have multiple addresses for a single protocol. A service with multiple base addresses for a single protocol scheme would fail to start running when activated. You could partially work around this limitation by supplying base address prefix filters. A prefix filter allows you to pick one base address to use with your service for each protocol scheme.
<serviceHostingEnvironment> <baseAddressPrefixFilters> <add prefix=”http://www.example.com:80”/> </baseAddressPrefixFilters> </serviceHostingEnvironment>
After filtering, other pages in the site could use any of the addresses while still allowing the WCF service to run. However, the WCF service would only be listening on the portion of addresses that start with the path defined by the filter.
In 4.0 you can enable support for multiple bindings with IIS without having to pick a single base address.
<serviceHostingEnvironment multipleSiteBindingsEnabled=”true” />
This feature for using multiple bindings with IIS is limited to HTTP protocol schemes though.
May and June ReMIX 2010 Events
ReMIX is an annual twist on the MIX conference that takes a small portion of the content presented at MIX and combines it with new content and local speakers for a variety of sites around the world. There are generally ReMIX events announced throughout the year starting shortly after the MIX conference is held in Las Vegas.
Here are a few that have been announced so far:
Atlanta, Georgia is hosting a ReMIX conference May 8th for the southeastern United States
Moscow is hosting ReMIX May 21st along with a DevConf WebCamp earlier in the week
Melbourne is hosting ReMIX during June 1st and 2nd
And of course you can always watch the online videos recorded from the original MIX conference.
Windows Server AppFabric Refresh and Videos
Windows Server AppFabric provides management, monitoring, and other component services for WCF services using .Net 4. The beta 2 release of AppFabric came out a few weeks ago using the release candidate of .Net 4. Now that the final version of .Net 4 is available, you can get a refreshed version of Windows Server AppFabric Beta 2. You should completely uninstall any preview releases of .Net 4 and AppFabric before installing the final version of .Net 4 and the updated AppFabric beta.
If you haven’t tried Windows Server AppFabric, then there are some new Channel 9 videos available that walk through the features in the AppFabric dashboard as an introduction.
HTTPS Host Name for IIS
The configuration of an IIS site includes the ability to associate a host name with a particular site definition. For HTTP traffic this allows multiple web sites to be hosted at the same IP address and port, with the true domain name of the site mapped using the host name header. For example, if you have a limited number of IP addresses available and many domains that you want to host all on port 80, then you can specify a different host header for each site to distinguish the traffic.
However, for HTTPS the ability to provide host headers is disabled in the interface. There are two different (but related) reasons for this difference in behavior.
First, the typical HTTPS certificate is usually generated for a single fully qualified domain name. Getting a certificate that has a wildcard in the domain name or that has multiple listed common names usually requires additional requirements by the certificate authority before being issues. If you didn’t know to ask for this, then you probably don’t have the right type of certificate for hosting multiple HTTPS sites. A certificate against a single name doesn’t need configuration to be used because there is only one valid value that you could use it with.
Second, the infrastructure for processing certificates is actually bound to the IP address and port rather than the site. Certificate processing is largely complete by the time the HTTP kernel driver hands the request off to the web server. A decision about how to process the message needs to be made before IIS has a chance to apply its service configuration. This is not a simple layering problem of the implementation but rather something more fundamental about the protocol. In order for IIS to extract the information from the message that it needs to identify the site, the certificate processing needs to be done first so that the decrypted message can be examined. Changing the order of steps to solve the original problem would simply create a new problem.
Fortunately, the loose coupling between the HTTP driver and the IIS host header configuration aids in solving the problem of order. If you have a properly provisioned certificate, then the message can be seen to match one of the provided names even if the HTTP driver doesn’t know which. This allows the mapping to be deferred until the site configuration and decrypted information are both available. The interaction between the different layers of the stack pushes the scenario beyond the limits of what the user interface makes easy though.
Schema Errors Extending Configuration
After adding a custom binding element to configuration as a binding element extension, Visual Studio reports any use of the binding element in app.config as a schema violation. Is something wrong with the binding element?
No, as long as the binding is able to be instantiated when you run the service you know that the binding element extension is working correctly. Visual Studio reports a configuration extension as a schema violation because the resulting configuration file will contain elements that are not a part of the original schema definition for a .config file.
If you’d really like to eliminate the schema violations, then you can modify the schema files that Visual Studio uses to match your installed configuration extensions. Under the Visual Studio installation directory is the path \Xml\Schema\ which contains the reference definition for schemas. The definition for .config is part of the monstrously large DotNetConfig.xsd schema file. There is a version of the schema file for each previous .Net version as well. You can update the schema to customize how validation works in the editor but very few people bother to do this.
Network Tracing Betas
Two frequently used network diagnostic tools have gotten beta updates this week.
Network Monitor is an adapter level capture program that can record and analyze protocol traces. If you join the Connect beta program for Network Monitor 3 you can get access to the latest Network Monitor 3.4 beta release. Network Monitor 3.4 has a number of improvements to the user interface, filtering system, and the included set of protocol parsers.
Fiddler is an HTTP proxy server that allows you to intercept and modify HTTP traffic for applications in a variety of ways. The Fiddler 2.2.9 beta is available for download and includes some significant improvements to performance and connection use.
Optional Xml Fields
When using DataContractSerializer with a data member that has IsRequired set to false, the generated schema has minOccurs of 0. However, when using XmlSerializer with an XML element that has IsNullable set to true, the schema has minOccurs of 1. Instead, the schema has nillable set to true. How do I get the XmlSerializer behavior to match DataContractSerializer?
This difference in schema is due to differing ways of representing the lack of a value.
The schema attribute minOccurs is the minimum number of times that the named element must appear for the document to be valid. When minOccurs is 0, then that means it is legal for the element to not appear at all. Therefore, you can represent the lack of a value by omitting the element.
The schema attribute nillable indicates whether the named element can be set to a special nil value that is not in the ordinary range of values for the type of the element. When an element is set to nil, then that means the writer intentionally provided no value. Therefore, you can represent the lack of a value by saying the value is nil.
The DataContractSerializer IsRequired mechanism uses the first approach for representing the lack of a value while the XmlSerializer IsNullable mechanism uses the second approach. However, XmlSerializer also has a way of using the first approach.
The XmlSerializer pattern used to omit an element is to associate the element with a separate Boolean value indicating whether the element should be omitted. The association is done by name like this:
[XmlElement] public string Id;
[XmlIgnore] public bool IdSpecified;
The three requirements for XmlSerializer to make the association are:
- The name of the associated field is the same as the element field with the suffix Specified
- The associated field is a Boolean value
- The associated field is marked XmlIgnore
Fix for Generating Metadata Behind a Router
When generating metadata to describe a service, an address is published for the location at which the service can be reached. This is the address to which a client of the service should address a message.
Ordinarily, the metadata address is obtained by looking at the address at which the service is listening for messages. However, if you have a router that forwards messages from a publicly addressable location to a service at a privately addressable location, then the address that the service is listening at is different than the one that should appear in the metadata. A client should send messages to the router’s publicly addressable location rather than trying to send messages to the service directly.
We created a fix for .Net 3.5 to allow the metadata generation for the service to use the address to which the metadata request was sent instead of the address at which the service is listening. After installing the fix, you can add a new service behavior called UseRequestHeadersForMetadataAddressBehavior to your service configuration. The metadata exchange endpoint looks for an instance of this behavior in the service description when generating metadata. In addition to changing the generated address, the behavior also provides a limited way to further remap the port portion of the address.
This fix is available for download from KB article 971842.
Silverlight 4 Business Application Course
The Silverlight 4 business application training course is a set of videos and labs divided into eight modules for learning about building business applications with Silverlight. The primary focus of the training course is to learn about the new features in Silverlight 4. Existing preliminary material is gathered together to go over the features that are now available.
The eight modules cover: an introduction to Silverlight 4, WCF RIA Services, authoring basic controls, interacting with system resources, advanced controls, printing, running out of browser applications, and MEF.
You can work through the course either online or by downloading a large chunk of the resources to run locally.
Moonlight 3 Preview 6
Moonlight, the Linux version of Silverlight, has produced its sixth preview release of Moonlight 3. I don’t announce every release that they do because the team has a very short development cycle; the last announcement I did was for the first preview release of Moonlight 3 and that was less than three months ago. The reason I picked this preview to call out is because it’s the one that gave me a “past the halfway mark” feeling relative to the goals they originally announced for Moonlight 3. I’m not quite ready to put a guess in for when they’ll be done though.
Some of the improvements from the last few months have been around text control styling, smooth streaming, socket support, compatibility with popular sites, and integration with Firefox and Chrome. Moonlight 3 Preview 6 is largely on the way to compatibility with the feature set of Silverlight 3.
You can download the Moonlight preview from the Mono site as well as file a bug report for any issues you find.
WCF RIA Services Release Candidate 2
Late last week a second release candidate for WCF RIA Services was released. RIA Services are an application design pattern that lives between ASP.NET and Silverlight in a multi-tier architecture. Inside RIA Services you can host application logic for data access control, queries, and other data operations. Integration with Silverlight components and controls allows for data validation and access control to automatically be made available to the client.
The update from the release candidate at this year’s MIX event includes bug fixes, improvements to tracing and debugging, and some minor feature enhancements. This release candidate also has a corresponding April update to the RIA Services toolkit.
This installation requires having previously installed Visual Studio 2010 and the Silverlight 4 Tools.
- WCF RIA Services Release Candidate 2 for Silverlight 4 and Visual Studio 2010
- WCF RIA Services Toolkit April 2010
Download the Moving to Visual Studio 2010 Draft
Moving to Visual Studio 2010 is a developer guide for learning about the new features of Visual Studio 2010. The final version is planned to come out in a few months. The content so far is as much about the libraries released at the same time as Visual Studio 2010, such as MEF and ASP.NET MVC 2, as about the Visual Studio program itself.
Different parts of the book tell the story from each of the perspectives of Visual Studio 2003, Visual Studio 2005, and Visual Studio 2008. The preview draft is of the material for Visual Studio 2005.