Sunday, November 23, 2008

Collection Classes in .NET 3.5

pencil icon, that"s clickable to start editing the post

Being able to easily handle collections both in terms of functionality and performance is central to any computer language. Going from plain arrays with memory handling i C++ to the STL collection classes was a hurge lap forward. I practice I've used very few variants since much functionality is often handled in the persistens layer. C# and .NET has plenty of built-in collection classes, and it's practical to know and needed for the 70-536 Exam:

Developing applications that use system types and collections (15 percent)

  • Manage a group of associated data in a .NET Framework application by using collections.
    May include but is not limited to: ArrayList class; Collection interfaces; Iterators; Hashtable class; CollectionBase class and ReadOnlyCollectionBase class; DictionaryBase class and DictionaryEntry class; Comparer class; Queue class; SortedList class; BitArray class; Stack class
  • Improve type safety and application performance in a .NET Framework application by using generic collections.
    May include but is not limited to: Collection.Generic interfaces; Generic Dictionary; Generic Comparer class and Generic EqualityComparer class; Generic KeyValuePair structure; Generic List class, Generic List.Enumerator structure, and Generic SortedList class; Generic Queue class and Generic Queue.Enumerator structure; Generic SortedDictionary class; Generic LinkedList; Generic Stack class and Generic Stack.Enumerator structure
  • Manage data in a .NET Framework application by using specialized collections.
    May include but is not limited to: Specialized String classes; Specialized Dictionary; Named collections; CollectionsUtil; BitVector32 structure and BitVector32.Section structure

In this post I'll run through the classes (and save the Interfaces, Base classes and further functionality for another post). First the four relevant namespaces:

System.Collections
The System.Collections namespace contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hash tables and dictionaries.
System.Collections.Generic
The System.Collections.Generic namespace contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
System.Collections.ObjectModel
The System.Collections.ObjectModel namespace contains classes that can be used as collections in the object model of a reusable library. Use these classes when properties or methods return collections.
System.Collections.Specialized
The System.Collections.Specialized namespace contains specialized and strongly-typed collections; for example, a linked list dictionary, a bit vector, and collections that contain only strings.

Collection Classes

System.Collections

ArrayList
Implements the IList interface using an array whose size is dynamically increased as required.
BitArray
Manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).
Hashtable
Represents a collection of key/value pairs that are organized based on the hash code of the key.
Queue
Represents a first-in, first-out collection of objects.
SortedList
Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
Stack
Represents a simple last-in-first-out (LIFO) non-generic collection of objects.

System.Collections.Specialized

HybridDictionary
Implements IDictionary by using a ListDictionary while the collection is small, and then switching to a Hashtable when the collection gets large.
ListDictionary
Implements IDictionary using a singly linked list. Recommended for collections that typically contain 10 items or less.
NameValueCollection
Represents a collection of associated String keys and String values that can be accessed either with the key or with the index.
OrderedDictionary
Represents a collection of key/value pairs that are accessible by the key or index.
StringCollection
Represents a collection of strings.
StringDictionary
Implements a hash table with the key and the value strongly typed to be strings rather than objects.

System.Collections.ObjectModel

ObservableCollection(T)
Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.
ReadOnlyObservableCollection(T)
Represents a read-only ObservableCollection(T).

System.Collections.Generic

Dictionary(TKey, TValue)
Represents a collection of keys and values.
HashSet(T)
Represents a set of values.
KeyedByTypeCollection(TItem)
Provides a collection whose items are types that serve as keys.
LinkedList(T)
Represents a doubly linked list.
List(T)
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.
Queue(T)
Represents a first-in, first-out collection of objects.
SortedDictionary(TKey, TValue)
epresents a collection of key/value pairs that are sorted on the key.
SortedList(TKey, TValue)
Represents a collection of key/value pairs that are sorted by key based on the associated IComparer(T) implementation.
Stack(T)
Represents a variable size last-in-first-out (LIFO) collection of instances of the same arbitrary type.
SynchronizedCollection(T)
Provides a thread-safe collection that contains objects of a type specified by the generic parameter as elements
SynchronizedKeyedCollection(K, T)
Provides a thread-safe collection that contains objects of a type specified by a generic parameter and that are grouped by keys.
SynchronizedReadOnlyCollection(T)
Provides a thread-safe, read-only collection that contains objects of a type specified by the generic parameter as elements.

What should I choose and when?

I am no expert, but I would use on of the generic variants if possible, since I like strong types (type-safe) and I even more hate those pesky casts from Object into a magical and sometimes unknown class. Infact I can't see no reason not to, since if it's bumped together in a collection I expect them to be related at least by an Interface.

In C++ I got away with something like 92% Vectors, 6% Maps and a minority of other collections from STL. In practical C# I'll probably do more or less the same, but for the Exam I'll probably have to learn the more odd ones, not that I mind using a Queue or Stack where it fits. My aversion for linked Lists has probably something to do with it being a little harder to iterate in C++ and this is most definitely much easier in the newer C#/.NET.

I've later found a good resource on Collection Classes (C# Programming Guide) that among other has a reference to the guide: Selecting a Collection Class.

Read more

Thursday, November 20, 2008

Setting the aim for Exam 70-503, MCTS: Microsoft .NET Framework 3.5 – Windows Communication Foundation Application Development

pencil icon, that"s clickable to start editing the post

As i revealed in Considering becomming a Microsoft Certified Technology Specialist - first up 70-536 and further inspired by WS-federation is enabled with 'Geneva' and obviously also SAML V2.0 support i've ecided to go for "MCTS: Microsoft .NET Framework 3.5 – Windows Communication Foundation Application Development (Exam 70-503)".

I know that I'll have To pass 70-536 also but I hope that 70-503 will pull the train for me since It's close to area of interest and work. To help me get there I've ordered a couple of books from Amazon among them: MCTS Self-Paced Training Kit (Exam 70-503): Microsoft® .NET Framework 3.5 Windows® Communication Foundation (PRO-Certification) (Hardcover) that I'll be receiving within the next week.
Other resources should be the documentation from MSDN on Windows Communication Foundation and an elaborate guide patterns & practices Improving Web Services Security Guide.

Contents of "Microsoft .NET Framework 3.5 – Windows Communication Foundation Application Development" (Exam 70-503)

In the Preparation Guide for Exam 70-503 the Audience profile as:

Candidates for Exam 70-503 TS: Microsoft .NET Framework 3.5 – Windows Communication Foundation Application Development work on a team in a development environment that uses Microsoft Visual Studio 2008 and Microsoft .NET Framework 3.5 to build distributed applications. Candidates should have at least one year of experience developing distributed applications by using technologies such as XML Web services, .NET Remoting, and Windows enterprise services. Additionally, candidates should be able to demonstrate the following by using Windows Communication Foundation (WCF).

  • A solid understanding of WCF in the context of the Microsoft .NET Framework 3.5 solution stack
  • Experience creating service model elements
  • Experience using WCF to support Web services specifications standards
  • Experience integrating WCF services with Windows enterprise services such as Message Queuing (MSMQ) and COM+
  • Experience configuring and deploying WCF applications

Apart from the fact that I've done zip on ".NET Remoting, and Windows enterprise services" I'm still optimistic but haven't set a time plan for myself yet. The more detailed description is (with Id's for my own reference):

  1. Creating Services (19 percent)
    1. Define Service contracts.
    2. Define Data contracts.
    3. Define Operation contracts.
    4. Define Message contracts.
    5. Process generic messages.
  2. Exposing and Deploying Services (23 percent)
    1. Create and configure service endpoints.
    2. Manage consistency between life cycle, sessions, concurrency, and bindings.
    3. Host a service in a managed application.
    4. Host a service on a Web server.
    5. Create custom behaviors.
  3. Instrumenting and Administering Services (11 percent)
    1. Implement end-to-end service tracing.
    2. Monitor service health.
    3. Log messages.
    4. Dynamically configure the service by using the service model.
    5. Implement inspectors.
  4. Consuming Services (16 percent)
    1. Create a service proxy.
    2. Configure the client endpoint.
    3. Call a service by using a service proxy.
    4. Handle exceptions on clients.
    5. Consume non-WCF services.
  5. Securing Services (16 percent)
    1. Implement transport-level security.
    2. Implement message-level security.
    3. Authenticate clients.
    4. Authorize clients.
    5. Impersonate clients.
  6. Managing the Service Life Cycle (15 percent)
    1. Manage instances.
    2. Manage sessions.
    3. Manage transactions.
    4. Manage concurrency.
    5. Manage consistency between instances, sessions, transactions, and concurrency.

There's certainly a good deal of Identity Management and federation standards involved, but the Exam does not cover Geneva. The other way round a solid understanding of WCF should come in handy if using Geneva.

Read more

WS-federation is enabled with 'Geneva' and obviously also SAML V2.0 support

pencil icon, that"s clickable to start editing the post

Yesterday I had the pleasure of attending an Architecture session with Vittorio Bertocci on Identity Management and the Geneva server/Framework. Though he claimed not to be trustworthy since he's both Italian and long-haired, I found it quite the opposite. His presentation was right-paced and with a fine live demo that he handlede greatly with his tablet (envy). It inspired me to ask enough questions that I somehow qualified myself for a copy of his book Understanding Windows CardSpace: An Introduction to the Concepts and Challenges of Digital Identities, which he unfortunately didn't have with him!

The talk was on all the Geneva stuff (earlier Zermatt, not that I knew). My take away was that ws-federation (and ws-trust with it) now had full product support and that MS sees that combined with the claim-thing as a big solver for the architectual complexity of handling identity. There were several questions on SAML V2.0 support, that has had quite a pickup in Denmark. The short answer was that IdP Lite support was there and that SP Lite was expected to follow later. I was disappointed to hear this but today I found a positive source that not only is SP Lite implemented, it has undergone som interoperability tests with Ping and underway is maybe even a conformance test with Liberty - it can all be read in “Geneva” SAML Interop … With a Lot of Help from Our Friends.

I still haven't found time and interest to delve in ws-federation and ws-trust, but it's becoming much more relevant. As for the clash between ws-federation and SAML at Oasis (Federation power fight in the backyard of OASIS) I haven't read or heard anything since but my best bet is that SAML V2.o is here to stay, but that I expect development to happen in lieu of ws-federation, since it's wider and has most of the big players. Also Sun who's had a central part in SAML is diminishing as a player.

There's more info on '/geneva': Identity Management ("Geneva" Simplifies User Access to Applications and Services), but apparently no all information is available yet, since I could not get any of the downloads from Geneva Whitepapers and Datasheet, except blank pages (in any browser). Another good place to look is the coverpages: Microsoft 'Geneva' Framework Supports SAML 2.0, WS-Federation, and WS-Trust.

The best language flower of the day was not from Vittorio, who had a solid but understandable accent, but by the host Rene Løhde that at the start of the session told Vittorio that when it was time for the break he would give him the stare and then he would break him! with Vittorio commenting that it didn't sound nice.

I've noticed that Rene has a related TechTalk next week Identitetshåndtering på nettet med Geneva FX (tidl. Zermatt).

Read more

Monday, November 17, 2008

Considering becomming a Microsoft Certified Technology Specialist - first up 70-536

pencil icon, that"s clickable to start editing the post

Daddy's got a brand new car with the acronym VS2008 and it runs on C# 2008 and .NET 3.5. I haven't really done any development i .NET since the good ol' days of platform breaking .NET 1.0. Java's fine for me but I would like to widen my knowledge since I both found it easy to use and productive and at the same time adoption seems to rise (judging from the number of vacancies with .NET in the job description). Running for a certification might lead the way into the inner workings of .NET and give me something for my CV since I currently do to less coding (In my own eyes).

Nowadays the first step is MCTS: Microsoft Visual Studio 2008 and any matter which of tracks I'll go for (probably WCF og ASP.NET) I'll need to pass Exam 70-536: TS: Microsoft .NET Framework – Application Development Foundation. There's a little confusion about this one since it used to be for .NET 2.0 but has be updated for 3.5 (both still in play for VS2005/VS2008) and reading about the 70-536 exam on the Microsoft Learning site doesn't make this much clearer but according to Gerry O'Brien's Get Ready for the ASP.NET 3.5 MCTS Exam and not the least his own comment:

The exams for 3.5 were recreated from scratch. We invite subject matter experts from the industry into a focus group and create the exam structure and coverage based on how the product or technology is used in the industry.

We do not base our exams solely on product features. The features come into play as a result of the tasks that are performed based on our SME input and as a result, the exam may or may not include content that is similar in nature to what was on an exam for 2.0.

To prepare for an exam, never assume anything about the content but rather use the prep guides found online to understand the areas that will be covered on the exam and prepare accordingly.

So it's new but might be close to being the same - fair enough the basics are still the same.

The exam costs 1600 kr. in Denmark which isn't exactly cheap but as I recall the SCJP costed somewhere similar.

What's the exam about

The material covered in the exam spans seven areas:

  • Developing applications that use system types and collections (15 percent)
  • Implementing service processes, threading, and application domains in a .NET Framework application (11 percent)
  • Embedding configuration, diagnostic, management, and installation features into a .NET Framework application (14 percent)
  • Implementing serialization and input/output functionality in a .NET Framework application (18 percent)
  • Improving the security of .NET Framework applications by using the .NET Framework security features (20 percent)
  • Implementing interoperability, reflection, and mailing functionality in a .NET Framework application (11 percent)
  • Implementing globalization, drawing, and text manipulation functionality in a .NET Framework application (11 percent)

and I'm afraid that I'm pretty blank on many of them.

Study material

Considering that presently I can just find one book to directly support this exam: MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework Application Development Foundation, Second Edition (Paperback) (just out November 12, 2008) and that the former version MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework 2.0 Application Development Foundation (Hardcover) according to Derik Whittaker - "Taking the MCTS Test 70-536 -- That Sucked...." and the commenter's on his blog isn't that great.

The book Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition seems like the best book in general and is in fact a newer incarnation on the now seven years old C# and the .NET Platform (Paperback) that I keep in a box somewhere.

Many of the comments found strongly recommends taking/rehearsing text exams so I'll probably also have to get testking or measureup.

Read more

Saturday, November 8, 2008

The xml:lang attribute, it's use in XML Schema and SAML V2.0 Metadata

pencil icon, that"s clickable to start editing the post

The OASIS standard for Federated/Single Sign-On SAML V2.0 has a format for exhanging (meta)data about Identity/Service provider. The syntax is defined the XML Schema saml-schema-metadata-2.0.xsd and is futher described (the semantics) in saml-metadata-2.0-os.pdf. In this blogpost I'll focus on the less important use of xml:lang in this format and look at the general use of it.

Reusing xml:lang in XML Schema

It's the contents of the Organization that is parametrized with the xml:lang attribute:

This involves importing the namespace in the XML Schema (it'a all ready defined and we just want to use it).

   19     <import namespace="http://www.w3.org/XML/1998/namespace"
   20         schemaLocation="http://www.w3.org/2001/xml.xsd"/>

This it then used ind the definitions of two elements:

The localizedNameType complex type extends a string-valued element with a standard XML language attribute.

   36     <complexType name="localizedNameType">
   37         <simpleContent>
   38             <extension base="string">
   39                 <attribute ref="xml:lang" use="required"/>
   40             </extension>
   41         </simpleContent>
   42     </complexType>

The localizedURIType complex type extends a URI-valued element with a standard XML language attribute.

   43     <complexType name="localizedURIType">
   44         <simpleContent>
   45             <extension base="anyURI">
   46                 <attribute ref="xml:lang" use="required"/>
   47             </extension>
   48         </simpleContent>
   49     </complexType>

This is then put to use in the definition of Organization:

The <Organization> element specifies basic information about an organization responsible for a SAML entity or role. The use of this element is always optional. Its content is informative in nature and does not directly map to any core SAML elements or attributes.

  120     <element name="Organization" type="md:OrganizationType"/>
  121     <complexType name="OrganizationType">
  122         <sequence>
  123             <element ref="md:Extensions" minOccurs="0"/>
  124             <element ref="md:OrganizationName" maxOccurs="unbounded"/>
  125             <element ref="md:OrganizationDisplayName" maxOccurs="unbounded"/>
  126             <element ref="md:OrganizationURL" maxOccurs="unbounded"/>
  127         </sequence>
  128         <anyAttribute namespace="##other" processContents="lax"/>
  129     </complexType>
  130     <element name="OrganizationName" type="md:localizedNameType"/>
  131     <element name="OrganizationDisplayName" type="md:localizedNameType"/>
  132     <element name="OrganizationURL" type="md:localizedURIType"/>

The documentation contains a metadata example for a Service Provider where the Organization is defined as:

   55   <Organization>
   56     <OrganizationName xml:lang="en">
   57       Academic Journals R US
   58     </OrganizationName>
   59     <OrganizationDisplayName xml:lang="en">
   60       Academic Journals R US, a Division of Dirk Corp.
   61     </OrganizationDisplayName>
   62     <OrganizationURL xml:lang="en">
   63       https://ServiceProvider.com
   64     </OrganizationURL>
   65   </Organization>

and note that the xml namespace is predefined, it would be an error to explicitly redefine it.

xml:lang and it's use in XML document schemas

In section 2.12 Language Identification of the XML Specification, it says:

In document processing, it is often useful to identify the natural or formal language in which the content is written. A special attribute named xml:lang may be inserted in documents to specify the language used in the contents and attribute values of any element in an XML document. In valid documents, this attribute, like any other, must be declared if it is used. The values of the attribute are language identifiers as defined by [IETF RFC 3066], Tags for the Identification of Languages, or its successor; in addition, the empty string may be specified.

In the FAQ: xml:lang in XML document schemas. In the bye the way it says how to use xml:lang in XML Schema:

XML Schema requires that the xml namespace be declared and imported before using xml:lang (and other xml namespace values)

For a small discussion on the reuse of attributes form the XML Specification you can look as this mail thread from xml-schema list.

The also a section on When to use your own element or attribute:

When the language value is really an attribute of or metadata about some external content, then xml:lang is not an appropriate choice. In these cases you want to store language information, but the language doesn't refer to the content of the XML document (or included content, such as images, which are processed as part of the document) directly. In this case you should define an element or attribute of using a different name and not use the xml:lang attribute. The value of the element or attribute should use RFC 3066 (or its successor), just like xml:lang.

An ups, this disqualifies it's use on OrganizationURL since this is referring to another document. In real life this is a no-problem, and if not for anything else then because the Organization element is optional.

The value of reuse

A more interesting dicussion is the value of reuse, which varies greatly from both where it's applied and used.

The XML Schema itself reuses the type localizedNameType several times as an syntactic component, since it very generic only constraining to Name something and with an attribute to described the language. The URL variant is only used once and in general since an empty value is allowed I would have liked the attribute to be optional instead of required.

The value of reusing xml:lang could be argued as minimal, since it would be easy to redefine without to much struggle, and the level of generic support for this attribut is in my opinion limited and tied to the domain/application use.

Update! Since making this post I've had some experience with it in XMLBeans which actually has some built in checks that surpass the definition in the xml.xsd:

   92  <xs:attribute name="lang">
   93   <xs:annotation>
   94    <xs:documentation>Attempting to install the relevant ISO 2- and 3-letter
   95          codes as the enumerated possible values is probably never
   96          going to be a realistic possibility.  See
   97          RFC 3066 at http://www.ietf.org/rfc/rfc3066.txt and the IANA registry
   98          at http://www.iana.org/assignments/lang-tag-apps.htm for
   99          further information.
  100 
  101          The union allows for the 'un-declaration' of xml:lang with
  102          the empty string.</xs:documentation>
  103   </xs:annotation>
  104   <xs:simpleType>
  105    <xs:union memberTypes="xs:language">
  106     <xs:simpleType>
  107      <xs:restriction base="xs:string">
  108       <xs:enumeration value=""/>
  109      </xs:restriction>
  110     </xs:simpleType>
  111    </xs:union>
  112   </xs:simpleType>
  113  </xs:attribute>

For one it checks that the overall syntax is correct, ex. It'll call it an error if I use da_DK instead of da-DK and doesn't allow for it to be empty like the xml.xsd states (which is fine by me since I personally dislikes empty elements and attributes in data-centric scenarios).

Language Identifiers (RFC 3066)

The page Using Language Identifiers (RFC 3066) is great for quick brush up. Being a Dane my interest is on the three examples for Denmark:

da-DK (Danish) de-DK (German)

da-DE (Danish)

That's for the majority speaking danish in Denmark, the minority speaking danish in Germany and german in Denmark. Since both Denmark and the choice for speaking danish is very liminite in geographic and individuals, it doesn't really make sense to me to go for anything other than da,da-DK or de,de-DE.

A great source for quick trip around Web Internationalization Standards and Practice is the presentation/tutorial [PDF] that can be found on that page.

Read more