Dictionary Classes Benchmarked

by kevin 7/13/2008 8:30:00 PM

A few days ago, I stumbled on an article by Amit Raz about the SortedList<K,T> on Dev102.com. In the article, which compares and contrasts the SortedList collection class in the .NET BCL to the SortedDictionary class, Amit concludes with, "So what is the SortedList good for? Beats me. I deem it useless." His conclusion seemed to be predicated on the fact that the Add() method would throw an exception if the programmer attempted to insert a duplicately keyed entry into a SortedList. However, this is documented behavior. And both the SortedList and the SortedDictionary exhibit that same behavior. An indexer exists on each of those collections that will allow the insertion of a duplicately keyed item. For both classes, duplicates replace the original values when using the indexer.

I had a difficult time following Amit's logic but he's a bright fellow so I wanted to find out if the SortedList really was useless as he had proclaimed. On this page, Microsoft provides a table that describes the benefits and relative drawbacks of these two seemingly similar classes. Long story short, the key advantages of the SortedList<K,T> are that it uses less memory than the SortedDictionary<K,T> and that some of its members that return keys and values are indexed. OK, so the SortedList uses less memory. But what's that latter claim about?

Well, the SortedList<K,T> has a few members that the SortedDictionary<K,T> does not. Among them are:

  • int IndexOfKey( K key )
  • int IndexOfValue( T value )

Kicking around in this class in Reflector, one sees that the internal storage for the SortedList<K,T> is a pair of arrays: one for the keys which is kept in sorted order and one for the values which is kept in insertion order. When using the IndexOfKey method noted above, Array.BinarySearch() is used to perform an efficient search for the desired key. However, the IndexOfValue method uses a brute force (O(n)) scan to find the requested value. Another special case advantage of the SortedList is that insertions are O(1) for data inserted in sorted order whereas for the SortedDictionary, the average insertion cost is around O(log n). In fact, for data already in sorted order, the SortedDictionary pays a bit of a penalty on insertion because of the required balancing of the tree structure used to store the information. More on that later. So, if you have small lists and the keys are already sorted before insertion, the SortedList might be a good choice. If your keys are not sorted, insertion into a SortedList could be as bad as O(n). So it may be that you have to know something about your data to use the SortedList in a way that makes it worthwhile. Not understanding your data, could make the SortedList worthless, as Amit claims.

I wrote a small test harness that exercises the SortedList<K,T> and SortedDictionary<K,T>. I've included a link to the source code below. The application runs a battery of tests using a small list of 1,000 items on each type of dictionary and the same battery using a large list of 40,000 items. The main window looks like this:

These results show an average test run on my Windows Server 2008 machine using the .NET Framework 3.5. For the small list of 1,000 items, the SortedList seems to be a bit more efficient than the SortedDictionary with respect to time, despite the fact that the keys are not in sorted order for that test. However, when it comes to the larger list of 40,000 items, the SortedDictionary is the clear winner for both insertions and removals. But what about memory? Remember that Microsoft's MSDN topic said that the SortedList can be more memory efficient? I put 10 seconds of time in between the 4 test groups shown on the screen shot above and ran the .NET memory profiler to see what was happening. It's not all that conclusive, in my opinion. Here's a graphic showing the Gen 0, 1 and 2 heap sizes over the lifetime of the test. Perhaps you can help me analyze what you see:

There is a very large spike during the third test in the Gen 1 heap size when the large data set of 40,000 values in placed into the SortedList. Most of that newly allocated memory seems to move to the Gen 2 heap when the last test kicks off, returning the Gen 1 heap almost back to it's former value. The internal implementation of the SortedDictionary is based on a private, internal class in System.Collections.Generic called TreeSet<T>. In an upcoming blog post, I will be examining the TreeSet<T> class in detail. It uses a special kind of binary tree implementation known as a red-black tree. Why Microsoft didn't expose this incredibly cool class, I don't understand. So I suppose I should do that, right? Until next time...

Source Code for the DictionaryTestHarness Application (6KB)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

BCL | C# | Debugging | Software Development

Accessing Web Services from Silverlight 2

by kevin 7/10/2008 10:39:00 PM

I presented tonight (10 July 2008) to the Richmond .NET User Group. We had a pretty good turnout, I'm guessing 40 to 45 developers. I gave this same presentation at my office today as a dry run and as a training opportunity within the company. It's so good to see the developer community eager to learn. I've attached my slides and the three demonstrations projects I used in this post. I'll be giving this same presentation to the Charlottesville .NET User Group next Thursday (17 July 2008). The abstract we put on both user group websites follows:

Silverlight is a client-side technology. So it’s not really a part of your SOA strategy, right? You may want to think twice about that. SOAP and WSDL support are coming to the web desktop via Silverlight. And Silverlight has good client support for REST+ JSON/POX and RSS/ATOM-based web services, too. During this discussion, we’ll dive into data serialization, security and cross-domain access policy capabilities inside Silverlight 2 Beta 2. We also talk about the nuances and pitfalls of provisioning your web services for an Internet audience. This presentation will be heavy on coding, demonstration and interactive discussion.

Powerpoint Presentation (289KB)

Twitter solution showing how to invoke a cross-domain RESTful service by way of an in-domain SOAP service bypassing the cross-domain access policy problem. (842KB)

REST solution showing how to create RESTful services in WCF and how to consume RESTful services in Silverlight (307KB)

Silverlight syndication solution showing how to consume cross-domain RSS and Atom feeds using the SyndicationFeed class. (11KB)

Windows Impersonator Class

by kevin 7/8/2008 11:34:00 PM

I wrote a handy little class called Impersonator a while ago to assist me in doing Windows impersonation. There are dozens of examples of this type of thing on the net. However, none of them were as "handy" as I prefer. By handy, I mean idiot-proof, of course. I like the IDisposable pattern a lot (I use the word pattern here loosely). IDisposable is usually meant to help idiots like me avoid mistakes. And in the case of changing the user identity on the running thread, forgetting to revert to the initial identity could be catastrophic. When combined with C#'s using statement, I get an extra measure of safety from forgetfulness or from rogue exceptions that might be thrown inside the impersonating code.

For the uninitiated, C#'s using statement makes IDisposable really hum by encapsulating the statement's code in a try/finally block where the IDisposable.Dispose method is called automatically and reliably. With my Impersonator class, you can now write code like this:

using (new Impersonator("domain", "username", "password"))
{
   // do whatever you want in here as domain\username
   // the security context will automatically revert on exit
   // when IDisposable.Dispose is called on the Impersonator
}

Pretty simple, huh? The code compiled by the C# compiler would actually look something like this:

Impersonator X = null;
try
{
   X = new Impersonator("domain", "username", "password");
   // do whatever you want in here as domain\username
   // the security context will automatically revert on exit
   // because of the Dispose call in the finally block
}
finally
{
   if (X != null)
      X.Dispose();
}

Now, if IDisposable were a real design pattern, there might be better compiler support. Wouldn't it be great that for classes implementing IDisposable, they could NOT be instantiated outside of a using statement context? That might be a bit restrictive in some cases but think about how fool-proof that would be. If you were required to instantiate IDisposable types within a using statement, you could guarantee that a type, which could be doing radical things like changing the identity on the running thread, would always clean up after itself. Alas, the C# team at Microsoft has been ignoring my plea for help.

Here's the code for the Impersonator class for your enjoyment. Let me know if you like it. I have many other gems like this one lying around.

using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;

namespace gotnet.Security
{
    /// <summary>
    /// Impersonate a local or domain user. This class uses the IDisposable
    /// pattern to automatically revert to the caller's original security
    /// context safely. When instantiated from within C# code, this class
    /// should always be constructed in a using statement to ensure that the
    /// disposal routine runs. If you are not using VB.NET, you should call
    /// the <see cref="Dispose"/> method in a Finally block.
    /// </summary>
    /// <example>
    /// <code>
    /// // enter the following block of code as user Fortunato
    ///
    /// using (new Impersonator("MyDomain", "Amontillado", "pAs5w0Rd"))
    /// {
    ///     // the running thread identity is now that of user Amontillado
    ///     // execute whatever you like here as the user Amontillado
    ///     // buy some bricks, some mortar, some good wine, etc.
    /// }
    ///
    /// // at this point, the thread identity has reverted to user Fortunato
    /// </code>
    /// </example>
    public class Impersonator : IDisposable
    {
        #region // DllImports
        [DllImport("advapi32.dll", SetLastError = true)]
        private static extern bool LogonUser(String lpszUsername,
            String lpszDomain, String lpszPassword, int dwLogonType,
            int dwLogonProvider, ref IntPtr phToken);

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        private static extern bool CloseHandle(IntPtr handle);
        #endregion // DllImports

        private readonly IntPtr tokenHandle = new IntPtr(0);
        private readonly WindowsImpersonationContext impersonatedUser; 

        /// <summary>
        /// Impersonate a user. When instantiated from within C# code, this
        /// class should always be constructed in a using statement to ensure
        /// that the disposal routine runs. If you are not using VB.NET, you
        /// should call the <see cref="Dispose"/> method in a Finally block.
        /// </summary>
        /// <param name="domainName">
        /// The domain to authenticate against. May be a machine name.
        /// </param>
        /// <param name="userName">
        /// The user name to authenticate with.
        /// </param>
        /// <param name="password">
        /// The password to authenticate with.
        /// </param>
        /// <exception cref="Win32Exception">
        /// The LogonUser operation failed.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        /// Windows returned the Windows NT status code STATUS_ACCESS_DENIED.
        /// </exception>
        /// <exception cref="OutOfMemoryException">
        /// There is insufficient memory available.
        /// </exception>
        /// <exception cref="System.Security.SecurityException">
        /// The caller does not have the correct permissions.
        /// </exception>
        public Impersonator(string domainName, string userName,
            string password)
        {
            const int LOGON32_PROVIDER_DEFAULT = 0;
            const int LOGON32_LOGON_INTERACTIVE = 2;
            tokenHandle = IntPtr.Zero; 

            if (!LogonUser(userName, domainName, password,
                LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
                ref tokenHandle))
            {
                int ret = Marshal.GetLastWin32Error();
                throw new Win32Exception(ret);
            }

            WindowsIdentity newId = new WindowsIdentity(tokenHandle);
            impersonatedUser = newId.Impersonate();
        } 

        /// <summary>
        /// Cleanup by reverting the user identity and closing any previously
        /// obtained handles. This method will be called automatically if you
        /// construct the Impersonator object from within a C# using statement.
        /// If you are using VB.NET, be sure to call Dispose from within a
        /// Finally block to make sure it happens. Failure to do so may leave
        /// the running thread in an unusable state.
        /// </summary>
        /// <exception cref="System.Security.SecurityException">
        /// An attempt is made to use this method for any purpose other than
        /// to revert identity to self.
        /// </exception>
        public void Dispose()
        {
            if (impersonatedUser != null)
            {
                impersonatedUser.Undo();
                impersonatedUser.Dispose();
            }
            if (tokenHandle != IntPtr.Zero)
                CloseHandle(tokenHandle);
        }
    }
}

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

C# | Security

Efficient Paging in SQL Server via LINQ

by kevin 7/6/2008 12:00:00 PM

UPDATE: I've included a videocast with this blog post. Let me know what you think. 

A few days ago, my buddy Justin Etheredge wrote a blog post about Efficient Paging in SQL Server. I was thinking about how transparent Language Integrated Query (LINQ) makes paging and I thought I'd blog about it. Two of the more interesting extension methods offered by LINQ are Skip() and Take(). You can use these extension methods to skip rows at the beginning of the query result and take only those you want to return. Sounds like paging to me. I wonder if Skip() and Take() used in combination with LINQ to SQL behave as efficiently as Justin's example? Let's take a look. Consider the following LINQ query:

var db = new AdventureWorksDataContext();
var query = from p in db.SalesOrderHeaders
  where p.SalesTerritory.Name.Equals( "Northeast" )
  select new {
    p.Contact.FirstName,
    p.Contact.LastName,
    TotalSales = p.SalesOrderDetails.Sum(
      o => o.OrderQty * o.UnitPrice )
};

This small example uses the AdventureWorks SalesOrderHeaders as the input sequence and shapes the output sequence to include the associated Contact's name parts and the total value of each order. The total value is computed as the OrderQty times the UnitPrice for each associated item in the SalesOrderDetails table. There is a filter placed on the query to restrict the results to orders placed in the 'Northeast' territory. This simple query shows how easy it is to filter, perform arithmetic and use the relationships in a LINQ to SQL data context to traverse table relationships. What does this query look like when it's compiled for execution on SQL Server?

SELECT
  [t2].[FirstName],
  [t2].[LastName],
  (
    SELECT SUM([t4].[value])
    FROM
    (
        SELECT
          (CONVERT(Decimal(29,4),[t3].[OrderQty])) * [t3].[UnitPrice] AS [value],
          [t3].[SalesOrderID]
        FROM [Sales].[SalesOrderDetail] AS [t3]
    ) AS [t4]
    WHERE [t4].[SalesOrderID] = [t0].[SalesOrderID]
  ) AS [TotalSales]
FROM [Sales].[SalesOrderHeader] AS [t0]
LEFT OUTER JOIN [Sales].[SalesTerritory] AS [t1]
  ON [t1].[TerritoryID] = [t0].[TerritoryID]
INNER JOIN [Person].[Contact] AS [t2]
  ON [t2].[ContactID] = [t0].[ContactID]
WHERE [t1].[Name] = @p0

You can see the territory filter applied as a WHERE clause. Note that even when a string literal is used in the C# code, LINQ to SQL still passes filtering variables as parameters. In this case, the territory name 'Northeast' is passed as a variable named @p0. This is always a good practice because it helps to thwart the injection of potentially malicious T-SQL into your query. We can see another interesting feature of LINQ to SQL in the T-SQL that is created called projection. Because the C# code shown above shapes the output sequence to only a few required columns, the LINQ to SQL engine is smart enough to T-SQL shape the query to return only what's needed. Projection often improves query performance and always improves transportation speed on the wire.

Finally, notice that the third column projected into the output sequence, i.e. the sum of each order's value, is instatiated as a two-part, nested sub-SELECT operation in the T-SQL statement. The inner SELECT does the math on the order quantity and price. The containing SELECT aggregates the line item totals and them filters them to the rows selected by the outer query. Nicely done, LINQ! Now, we see that this is a long list, returning thousands of rows. If this query is meant for human consumption, we should break it into smaller chunks to make it easier to handle. How do we do that in LINQ? Add this to the C# code shown before.

var _pageNum = 3;
var _pageSize = 20;
query = query.Skip((_pageNum - 1) * _pageSize).Take(_pageSize);

This modification uses the Skip() and Take() extension methods to skip 40 rows and take the next 20 rows. In other words, at 20 results per page, this query now returns the 3rd page. Though the magic of deferred execution, we can add the Skip() and Take() extentions at any time before we begin iterating over the result set. This comes in handy when you want to enable paging for human consumption but to disable it for B2B or ETL scenarios. Is the paged T-SQL query shown here efficient though? You tell me. Here the T-SQL that is produced:

SELECT
  [t6].[FirstName],
  [t6].[LastName],
  [t6].[value] AS [TotalSales]
FROM
(
  SELECT
    ROW_NUMBER() OVER
    (
      ORDER BY
        [t5].[FirstName],
        [t5].[LastName],
        [t5].[value]
    ) AS [ROW_NUMBER],
    [t5].[FirstName],
    [t5].[LastName],
    [t5].[value]
  FROM
  (
    SELECT
      [t2].[FirstName],
      [t2].[LastName],
      (
        SELECT
          SUM([t4].[value])
        FROM
        (
          SELECT
            (CONVERT(Decimal(29,4),[t3].[OrderQty])) * [t3].[UnitPrice] AS [value],
            [t3].[SalesOrderID]
          FROM [Sales].[SalesOrderDetail] AS [t3]
        ) AS [t4]
        WHERE [t4].[SalesOrderID] = [t0].[SalesOrderID]
      ) AS [value], [t1].[Name]
      FROM [Sales].[SalesOrderHeader] AS [t0]
      LEFT OUTER JOIN [Sales].[SalesTerritory] AS [t1]
        ON [t1].[TerritoryID] = [t0].[TerritoryID]
      INNER JOIN [Person].[Contact] AS [t2]
        ON [t2].[ContactID] = [t0].[ContactID]
    ) AS [t5]
    WHERE [t5].[Name] = @p0
  ) AS [t6]
WHERE [t6].[ROW_NUMBER] BETWEEN @p1 + 1 AND @p1 + @p2
ORDER BY [t6].[ROW_NUMBER]

If you read the query from the inside out, you'll see that on the inside it's essentially the same query that we saw before we added the paging feature. It has all the original SELECTs named t1 through t4 and is wrapped as a new result called t5. The SQL Server ROW_NUMBER() function is used to inject a row number into t5 ordered by all 3 projected columns. That looks a lot like the query Justin showed us in his blog post. Very efficient! The new result containing the row numbers is named t6.

Finally, the t6 result is filtered by a starting row number and ending row number using two new variables @p1 and @p2. For page 3 paged in 20 row chunks as shown above, these variables would have the values 40 and 59, respectively. LINQ to SQL injects these starting and ending row number parameters whenever you use Skip() and Take() together. Well, it almost always does that. If you happen to specify Skip(0), it reverts to the behavior that Take() uses without Skip() which is to use SQL Server's TOP() function instead. LINQ to SQL sure knows how to sweet talk SQL Server, don't you think?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

C# | LInQ | ORM | Software Development | SQL Server | SQL Server 2008

MVP Award for 2008

by kevin 7/2/2008 6:30:00 AM

I received Microsoft's MVP Award yesterday. I tried blogging about the experience at the end of the day but I didn't feel that I was ready to do it. The MVP Award is an unusual and very different kind of designation in the professional world. Many professional awards are about recognizing accomplishment. But the Microsoft MVP Award is about recognizing service. When you are singled out in this way, it's the community's method of saying, "Keep up the good work."

I've achieved many certifications in my career. I've held certifications from Sun, Oracle, IBM, Microsoft, HP, Siemens, Cisco and a few others. But I've never advertised them publicly because they were all my doing. I studied. I worked hard. I passed the certification exams. And I was a better developer and software architect for doing it. But, as a professional, I think those things are expected of me. So there was really no sense in wearing those certifications on my sleeve, in my opinion. To paraphrase the old adage, the proof is IN the pudding, not ON it, if you know what I mean.

The MVP Award, based on community and industry service, is not something you apply for. You get nominated by other MVPs and you go through a process of demonstrating what you've been up to for the past year. A review board checks you out (you can't hide from the search engines) and determines which MVP area of expertise you would fit into. Then, they determine among the other candidates in your group if your contributions to the community are exemplary. My MVP area of expertise is Visual C#, by the way. I think they picked the correct area for me because I know, love and promote the dickens out of C#. It's my favorite programming language in my career of 25 years so far.

It's a bit overwhelming to get the kind of support you need to win the MVP Award. When you receive "the magical e-mail" as some have called it, there's a stark moment of realization that you're standing on the shoulders of so many others who contributed to it. No MVP has ever achieved the title on his own. And I'm certainly no different. That's the way communities work. We lift each other up. I want to recognize a few folks who have lifted me up and encouraged me along the way to serve better within the Microsoft developer community:

These folks are my role models. In particular, I want to recognize Andy Leonard. If we weren't about the same age, I'd call Andy my techno-Dad. He's a father figure to all of us in the mid-Atlantic user group community, I believe. Andy is humble and brilliant, a rare combination. He's also the hardest working person I know. If I could follow Andy's lead to 50% efficiency, I know I would be successful, too. We are sorry to be losing him to Atlanta soon but he's leaving us in great shape. Thank you, Andy.

I send out a heartfelt thanks to these folks and the cast of hundreds who pour their time and energy into making the user groups, Code Camps and DevCamps throughout the mid-Atlantic region great successes. My profession would be just a job if it weren't for all of you. I look forward to serving you all in the year to come.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

C# | Professionalism | User Group

Justin Etheredge on Functional Programming

by kevin 6/3/2008 10:07:00 AM

For those of you in central Virginia, my friend Justin Etheredge is speaking to the Richmond .NET User Group this Thursday evening (6/5) at 6:30 p.m. EDT in the Markel Building’s first floor salon at 4600 Cox Road regarding:

Functional Programming Features of C# 3.0
 

Justin’s one of the brightest, hardest-working people I know. Check out his blog. Come out and meet Justin and network with some other software developers in the community. You won’t be disappointed.

Oh, and did I mention that the victuals will be a la Maggiano’s Little Italy? Mmmmm……

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

C# | Richmond | Software Development | User Group

StyleCop MSBuild Integration

by kevin 5/24/2008 8:10:00 PM
The Source Code Analysis team at Microsoft has a new blog. An article was published today by Jason Allor describing how to do MSBuild integration. I was going to write an article on this subject but why reinvent the wheel when Jason did such a good job?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

C# | Software Development | MSBuild

StyleCop - Microsoft Source Code Analysis for CSharp

by kevin 5/23/2008 11:07:00 PM

Microsoft released their source code analysis tool for C# today. It's called StyleCop, sort of like FxCop except for source code. This tool is available for download here. I've been getting some coding standards in place at SnagAJob.com and this tool comes at the perfect time. StyleCop works with both Visual Studio 2005 and 2008. After you install it, right-clicking on a file in the Solution Explorer or in the code editor will present a new option on the context menu entitled Run Source Analysis like this:

 

Clicking on the new option will run the source code analysis tool on the selected file(s) and produce a report in a new source analysis window that looks like this:

Notice that each StyleCop violation shown has a code beginning with the letters SA and followed by a numeric identifier. These codes defined by StyleCop rules are grouped in the following way:

  • Spacing rules - 1000 series
  • Readability rules - 1100 series 
  • Ordering rules - 1200 series 
  • Naming rules - 1300 series
  • Maintainability rules - 1400 series 
  • Layout rules - 1500 series 
  • Documentation rules - 1600 series

In the Source Analysis output window above, notice the error SA1027. That rule is not valid for me because, for my projects, I want to promote the use of tabs in source code whenever possible. So how can I turn this source code analysis error off? Well, in the installation folder for StyleCop, there is an XML file called Settings.SourceAnalysis. On my Longhorn installation, this can be found in D:\Program Files\Microsoft Source Analysis Tool for C#. On your system, that folder may be elsewhere. There is also an executable program named SourceAnalysisSettingsEditor.exe in the installation folder. If you run the settings editor, passing the name of the settings file as the first parameter, you'll see something like this:

Notice the seven items under C# in the tree on the left? Those are the seven rule groups I mentioned earlier. Since it's the rule for SA1027 that I want to disable, I simply open up the Spacing Rules node and locate that rule by its code. I need to uncheck the checkbox for that rule like this:

Clicking on the Apply button, the change is made to the XML settings file. Opening the XML file in Notepad, we can see the change documented this way:

From the XML, you can see that the Boolean property called Enabled has been set to False for the rule named TabsMustNotBeUsed within the SpacingRules. And running the source code analysis on my file(s) from Visual Studio again shows that the SA1027 error related to the use of tabs in the source code has been eliminated from the output. Nice. You can tune the master settings file for all the other rules to suit your needs in the same manner. I'll be blogging more about MSBuild integration and other cool stuff that StyleCop can do in the near future.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

C# | Software Development | StyleCop

Silverlight Web Services Slides and Sample Code from NOVA 2008.1 Code Camp

by kevin 5/17/2008 4:42:00 PM

This was the first time I gave this talk but the attendees seemed to be very receptive. The concerns about security in Silverlight, especially related to the protection of Intellectual Property (IP) and account access are really on peoples' minds. Based on the thoughtful question I received here and in Roanoke 2 weeks ago, I have decided to dedicate a whole chapter in my new book to Silverlight security principles.

In this talk, I discussed the various methods by which a Silverlight application can access remote web services. We didn't have time to get into RSS/Atom syndication but I'll be sure to cover it in a future talk. We also discussed cross-domain policy, another hot security topic, as it turns out. I showed how to enabled a WCF web service for RESTful delivery and then showed how to consume SOAP-based services from Silverlight. We closed by looking at the use of an in-domain, SOAP-based WCF service to act as a proxy for a cross-domain RESTful service that does not allow cross-domain access by policy. Here are the slides and sample code:

WCFRESTDEMO20080517.zip (18.89 kb) - sample code that shows how to make a WCF service RESTful; a Silverlight control is included that demonstrates how to use it; there is also a Digg.com downloader that demonstrates cross-domain functionality from Silverlight.

Twitter20080517.zip (25.59 kb) - sample code that shows how to consume an in-domain SOAP-based service from Silverlight; that SOAP-based service is really a proxy to a RESTful service at Twitter.com. And since Twitter.com's cross-domain policy doesn't allow access from my domain, this example shows how the server-side WebClient class can be used to circumvent the policy limitation.

Silverlight and WCF - NOVA Code Camp 2008.1.pptx (199.39 kb) - my PowerPoint slides from this discussion.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , , , ,

Architecture | C# | Silverlight | User Group | WCF

SuperSOAP Slides and Code from NOVA Code Camp 2008.1

by kevin 5/17/2008 4:28:00 PM

Accessing web services with SOAP can be just as easy as using REST with all the enterprise-class features you've come to expect from WSDL and SOAP. Who says that the cycle of metadata and proxy generation should be so hard? I gave a talk at the NOVA Code Camp 2008.1 that shows how by using the CodeDOM, and the ServiceModel.MetadataImporter, you can generate proxy code dynamically.

In this talk, I also showed how IronPython can be used to add a dynamic "lower edge" to a C# application to make it much more dynamic feeling. Finally, we finished with a discussion about features that may be added to Visual Studio 10 and the C# 4.0 language sprecification to make SOA achievable for many more developers. It was a lively discussion with lots of great questions. Here are the slides and the demo code:

ProxyGen20080517.zip (20.86 kb) - Sample code that demonstrates the use of IronPython and some custom CodeDOM code to avoid generating proxies for WCF integration via SOAP/WSDL. IronPython 2.0 Beta 1 or newer is required to compile this code.

Simple SOA with SuperSOAP by Kevin Hazzard.pptx (208.46 kb) - my PowerPoint slides from this discussion.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

Architecture | C# | DLR | IronPython | User Group | WCF

Powered by BlogEngine.NET 1.3.1.0
Theme by Mads Kristensen


Kevin's on Twitter / FriendFeed

W. Kevin Hazzard Welcome to Kevin Hazzard's Blog. Kevin is a Software Architect, Professor and Microsoft MVP specializing in C#, WCF, Silverlight and IronPython.

View Kevin Hazzard's profile on LinkedIn
Microsoft MVP Award Join me at CodeStock

Calendar

<<  July 2008  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Recent posts

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sign in