Welcome to MSDN Blogs Sign in | Join | Help

One of our mail goals in the Developer & Platform Evangelism is driving adoption of new technologies. To do so we're working with strategic customers which are interested in our stuff and help them implementing projects.

A few months ago we started working with derStandard.at, which is a well-known website in Austria, that is attached to one of the largest country-wide newspapers.

They're looking for new innovative ways to provide their content. That's why they evaluated Silverlight for a new InfoScreen application of theirs.

My colleague Mario Szpuszta and I supported derStandard.at in architectural design and prototyping of their project.

As a conclusion we've written a whitepaper on the architecture of the application and some best practices when working with Silverlight 1.0.

By the time we started the project, Silverlight 1.0 was the stable release of the new platform, that's why we've decided to use the first, JavaScript based version. derStandard.at will update their project to Silverlight 2.0 and so will we update the whitepaper (if you're interested in us doing so).

Feel free to download the whitepaper here and see our experiences with building an InfoScreen application with Silverlight 1.0.

Here are the slides and demos of my four sessions at the Austrian Launch Tour "Big>Days 2008".

Sorry for the delay.. I've been in a hurry during the last days.. So following the high demand, here they are :-)

In .NET 2.0 there is a cool class called SmtpClient within System.Net.Mail.

With this class you can send mail (at least I thought).
The requirement was to send an email over a server of one of our agencies.
The mail server was secured by username/password authentication. That's why I used the following code:

SmtpClient _client = new SmtpClient();
_client = new SmtpClient("smtp.myserver.at");

_client.UseDefaultCredentials = false;
_client.Credentials = new NetworkCredential("username", "password");

_client.Send("from@test.at", "to@test.at", "Hallo Welt", "Hallo max!!");
At execution of the last statement an exceptíon occurred:
image
The inner exception said "Invalid lenght for a Base-64 char array."
That didn't make any sense for me (nor helped me to fix the problem).
I had a look at the stack trace and found out, that the exception had occurred in a class called
SmtpNtlmAuthenticationModule.

image

So I used telnet to manually connect to the smtp server.

S: 220 smtp.myserver.at ESMTP
C: ehlo asd.com
S: 250-smtp.myserver.at Hello mypc.microsoft.com [xxx.xxx.xxx.xxx]
S: 250-SIZE 20971520
S: 250-PIPELINING
S: 250-AUTH PLAIN LOGIN CRAM-MD5 NTLM
C: AUTH NTLM <base64 encoded string>

S: 334 NTLM supported

Seemed like the server would support NTLM.. But.. when I looked up the NTLM-SMTP specification,I found out that the server should respond with

334 <NTLM supported as base64 encoded string>

So the problem obviously is, that "NTLM supported" was not a valid Base-64 encoded string (as the inner exception above also pointed out).

So how could this problem be solved...

I digged into the private members of the SmtpClient object and found a member called transport (of type SmtpTransport).

The SmtpTransport object had private members as well, and one of them was called authenticationModules - bingo!
image

This is an array of ISmtpAuthenticationModules like Negotiate, NTLM, Digest and Login.

Unfortunately SmtpClient always picks the most effective supported method (in this case NTLM). As NTLM was not working I needed a way to kick out NTLM of the list of supported auth methods.

So I used reflection to modify the array and "disable" (override) NTLM in the array. Here's what I did:

FieldInfo transport = _client.GetType().GetField("transport",
    BindingFlags.NonPublic | BindingFlags.Instance);

FieldInfo authModules = transport.GetValue(_client).GetType()
    .GetField("authenticationModules",
        BindingFlags.NonPublic | BindingFlags.Instance);

Array modulesArray = authModules.GetValue(transport.GetValue(_client)) as Array;
modulesArray.SetValue(modulesArray.GetValue(2), 0);
modulesArray.SetValue(modulesArray.GetValue(2), 1);
modulesArray.SetValue(modulesArray.GetValue(2), 3);

Voila!
image

Guess which smtp authentication module will be used now :-)

3 Comments
Filed under:

There are two nice helper apps included in Visual Studio 2008, which allow you to test-host your WCF service and invoke the methods to check they're working correctly.

The two apps are called WcfSvcHost.exe and WcfTestClient.exe.

By default they are set as default debugging activity in all WCF libraries. See how to get use of them:

  1. Create a new WCF Service Library
    image
  2. Build an interface "ISayMyNameService" with a class parameter named "Name"
    image 
  3. Implement a new service class
    image
  4. Change the class name of the hosted service in app.config:
    image
  5. Press F5 and start debugging.
  6. Voila - the WcfSvcHost is started an displays a successfull message. Click on the message for details:
    image
  7. At the same time the WcfTestClient got started and is now displaying a n UI for testing our simple WCF service. Double click on "HelloYou()" to invoke the method with parameters:
    image
  8. Press "Invoke" and wait for the service to complete. You'll then get back the response as a formatted list or in raw XML.
    image
  9. If you don't want the WcfTestClient, but your custom test client you can change the setting under the project properties:
    image

Last week in Las Vegas the upcoming version Silverlight 2 was presented.

Right now the Beta 1 is available for download.

As you probably already know, Silverlight is a browser plugin, which needs to be installed once by the end users.

If users get along Silverlight content embedded in a webpage, the app is downloaded and executed locally be the plugin (but displayed in the webpage).

Let me give you an overview of the functionality of the current beta:

.NET Support:

Silverlight 2 has a built in mini-version of the .NET Common Language Runtime. You can therefore build Silverlight 2 applications using C# or VB.NET (and even more..) without having .NET installed on the client before. That's why Silverlight .NET applications also work on the Mac.

Controls:

.NET support enabled a series of controls within Silverlight. Most important, focus handling is now supported - meaning you can control the currently active controls with the TAB key and input text or send other keys to controls.

The collection of built-in controls includes Textbox, Button, ItemsControl, FileOpenDialog as well as layout controls like Grid or StackPanel. The SDK includes other controls (which are not included in the core runtime and need to  be shipped with your app), they contain Checkbox, RadioButton, DataGrid, Calendar and more.

Styles & Templates:

Like with WPF you can now style your controls with a collection of property values for colors and other things. Moreover you can change the appearance of controls completely by specifying a control template for it. Data templates for visualization of custom objects are also available.

Databinding:

To bind specific properties to others you can now use databinding.

image

The sample shows how to bind a property (in contrary to WPF, the Path=.. syntax doesn't work right now). Set the data source with a DataContext property of the control or it's parents.

Networking:

You can either add a web reference to a HTTP or JSON web service or you can download data from any same-domain (or even cross domain) site URL. Client sockets are also supported.

LINQ:

With the help of LINQ to XML (in the SDK) you can query XML data source with the well known LINQ paradigm.

HTML Integration:

As Silverlight is always embedded within HTML it is crucial to provide a good interop story between HTML and Silverlight. You can access HTML objects out of Silverlight as well as access Silverlight methods out of JavaScript.

Local Storage:

Silverlight apps can store information in a local folder (which is somewhere in the user profile). Only the same app can read and write to and from this location. The size is limited, but increase can be requested. This is equal to Isolated Storage on the full .NET FX.

OpenFileDialog:

Local file system access is not permitted except Isolated Storage. With the help of the OpenFileDialog users can grant access to a specific file to the application (e.g. to use it for upload).

DeepZoom:

This technology, formerly known as "Seadragon" allows seamless zooming into high resolution images. Only the necessary parts of the images are transferred to the client to reduce network traffic.

 

If you want to play around with the current version, these links are essential:

By the way: In Q2 2008 a second Beta will be released, which will allow you to get online with your commercial projects - so start looking into Silverlight now!

2 Comments
Filed under: ,

Wednesday March 5th, Venetian Hotel, Las Vegas. Endless crowds are trying to get into the keynote room of MiX.

The first speaker is Ray Ozzie. As chief software architect of Microsoft, he talks about the overall strategy of Microsoft, providing a platform for consumer media applications as well as business applications over a variety of devices and the web.

Then the first announcement: We will provide what is called Microsoft SQL Server Data Services. Not to be confused with ADO.NET Data Services (Project "Astoria"), the SQL Server DS is an online storage service based on REST and SOAP webservices, which can be leveraged for your own applications. If you're interested in details see the session recording at visitmix.com, available for download later this week, or see Eugenio Pace's blog on this.

After that, Scott Guthrie, VP of developer division took over and started with an outlook to the future of web development with Microsoft:

One of these is the ASP.NET MVC framework, Dynamic Data Support as well as new AJAX extensions.

The next interesting announcement: The availability of Internet Explorer 8 Beta 1. You can already download it here! More details about new features to come on my blog.

Expression Studio 2 - is available as Beta version, with e.g. a great new Expression Web and Expression Blend for Silverlight 1.

To use Blend with Silverlight 2 a new version Expression Blend 2.5 March CTP is available.

Two other interesting announcements regarding Silverlight:

We are currently building a mobile version of Silverlight for use with Windows Mobile 6 devices. The first CTP will be available in Q2 2008 and...

Together with Nokia, Microsoft will provide versions of Silverlight for the Symbian powered devices Nokia S40 and S60 (no timeframe mentioned there).

So get back for the detailed postings on Silverlight 2 and IE 8.

If you are interested in sessions from mix, go to http://sessions.visitmix.com/

As MiX conference currently takes place here - I travelled "over" to Las Vegas. 15h of flight! That's really hard.

We departed at 10:50am in Vienna with Austrian Airlines towards Washington. Although economy class was as narrow as always we had nevertheless a lot of fun. They had small screens, where we could watch a lot of cool movies (like Disney's Pocahontas ;-)) as well as get ourselves ready for Las Vegas by playing Roulette (unfortunately without real money).IMAGE_076IMAGE_079 

I tried hard not to get asleep! So I spend my time with watching movies, reading Harry Potter (The order of the phoenix) and eating "delicious" food served by the stewardesses. Every now and then I had to walk around in the narrow airplane, otherwise my feet would have fallen off...

IMAGE_081 

(no comments..)

Finally we arrived.. no.. not in Las Vegas, but in Washington! After getting out of the aircraft we had to wait at the immigration counters to get our temp-immigration sheet. There was a long queue in front of the counter, which didn't get any shorter (although we were already waiting half an hour).

Thank god they were playing a nice ad-movie about the beauty of America ;-)

IMAGE_083

Finally an immigration officer told the waiting crowd, that their computers had hang up (I removed all "Microsoft" labeled items on my backbag and jacket in a hurry)..

So we had to wait and wait.. and watch the beautiful ad, about people talking of equal chances mixed with beautiful scenes of canions...

After what seemed like 100 repeats of the movie the computers were fixed again and we were finally allowed to immigrate.

Time to our connection flight was rather short, so we hurried to the boarding-gate, where we got into the airplane. Big mistake: The airline (TED) had nearly no meals (only pre-built snack boxes with chips,.. for lots of money..). So we were starving for the next 5 hours until we finally arrived in LAS VEGAS!!

IMAGE_082

I have to say Las Vegas is really nice! Especially the Venetian Hotel, where the MiX conference takes place. Everything here is styled like in Venice. They even have a small canal "grande" with condolas.

But will MiX be worthwhile 15 hard hours of travel.. ?! Let's see!

1 Comments
Filed under: ,

Hurrah! This year I'm allowed to attend MiX conference in Las Vegas! And I'm really excited!

I'm sure it will be a week of interesting sessions about Silverlight, Expression and other Web / UX Dev. topics!

You can also expect some interesting announcements around these topics.. :-)

So stay tuned to the news around MiX 08!

According to my weather sidebar gadget the temperature in Las Vegas will rise up until 22°C - so it's going to be a *hot week*!

Also it's my first time in Las Vegas, so I'm really curious seeing all the places I've only seen in lots of movies.

1 Comments
Filed under: , ,

Activities are the heart of WF. Together they form workflows, control the flow or do loops.

They can either be simple and atomic or composite.

Simple activities can do one thing as calling a database or web service, terminating the workflow or something else.

Composite activities consist of other activities - they have children within. If the "parent" composite activity is executed, it controls which children are executed in which order. The simplest composite activity, the sequence executes all it's children in a sequential way. A parallel activity consists of several sequences executes at the same time. But there are even more complex composite activities like IF statements, or loops. Even the entire workflow (either sequential or state machine based) is nothing more than a special activity with custom logic and additional properties.

Regardless of whether it is a simple or composite activity, each activity (at least somewhere above in the inheritance tree) inherits of Activity class.

public class MyActivity : Activity
{
    protected override void Initialize(IServiceProvider provider);

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext);
    protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext);
    protected override ActivityExecutionStatus HandleFault(ActivityExecutionContext executionContext,
                                                                Exception exception);
    protected override void Uninitialize(IServiceProvider provider);
}

What you get, is basic virtual methods, which you can override to provide the behaviour of your activity for this state.

Speaking of states - each activity implements a finite state machine. That means the activity is guaranteed to be in one of the following states:image State transitions may occur only in the directions of the arrows. White arrows are runtime-, yellow ones developer initiated.

This activity automaton displays the entire lifecycle of an activity:

  • At creation of the workflow Initialize() is called on all activities. They are afterwards placed in the Initialized state.
  • The activity is placed into Executing state and it's Executing() method is called. Within it the activity's actual work is done.
  • If an error occurs, the activity automatically transitions into Faulting, and HandleFault() is called.
  • Executing activities can be canceled by other activities to stop their execution.
  • Finally if all the execution, cancellation or fault handling work is done, the activity is closed by the developer.
  • Additionally there is the possibility to "undo" already executed activities. For that situation you can implement the ICompensatableActivity interface, which defines a Compensate() method. This method is called in the Compensating state and allows you to provide custom undo logic.

So to write you custom little activity, just inherit of the Activity base class and override the suitable methods for the states you want to provider logic for. To pass data from outside into the activity you can use DependencyProperties, a new concept in .NET 3.0 which are also used with WPF.

Here is a sample of a ConsoleWritelineActivity:

public class ConsoleWriteline : Activity
{
    public static DependencyProperty OutputProperty = DependencyProperty.Register("Output",
        typeof(string), typeof(ConsoleWriteline));

    public string Output
    {
        get
        {
            return ((string)(base.GetValue(ConsoleWriteline.OutputProperty)));
        }
        set
        {
            base.SetValue(ConsoleWriteline.OutputProperty, value);
        }
    }
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
    {
        Console.WriteLine(this.Output);
        return ActivityExecutionStatus.Closed;
    }
}
0 Comments
Filed under: ,

This week I had a session about advanced topics of Windows Workflow Foundation.

image

Some features I covered were

  • Workflow Execution Internals
  • External Services & Communication
  • Activity Execution Context
  • Persistence
  • Workflow States
  • Fault Handling
  • Transactions
  • Tracking
  • Advanced Authoring
  • Dynamic Updates

Feel free to download the slides and play around with the demos!

1 Comments
Filed under: , , ,

What made me think about this topic, was a combobox of shirt-sizes I came across during my speaker registration for TechEd 2007 in Barcelona, last November.

TShirt-Size

Why are there T-Shirts in sizes until X-X-X-X-X (5!) L ??

Well.. one possible reason: all shirts were smaller than usual. It turned out XL fitted me perfectly (while it is normally not my size).

1 Comments
Filed under:

While browsing around in the MSDN library, I stopped at a funny page about LINQ in VB 9 (http://msdn2.microsoft.com/en-us/library/ms364068(vs.80).aspx)

image

It's an eyecatcher, isn't it - but at least they're really explicit in their samples ;-)

Recently I've been recording a Demo-Video of our sticker-collection application. It's built on a soccer brand (for EM 2008) and is called "CollectIT".

It was built using Silverlight 1.0. Another cool thing is the LiveID integration.

And the most important thing - YOU can win a lot of prizes! Just visit http://www.microsoft.com/austria/collectIT/

Here's the video:

1 Comments
Filed under:

If you have an MSDN subscription, I suppose you get a lot of DVDs in different languages like Italian, German, Swedish, etc... every month.

Je ne parle pas français? - Non parlo italiano? - No hablo español?

Good news for all Europeans: You can restrict the languages of DVDs delivered to you!

1.) Go to https://microsoft.eu.subservices.com/msdn/default.aspx

2.) Login with your Firstname / Lastname, Email & Subscriber-ID as printed on your MSDN card.
clip_image001

3.) Select "Subscription Information"
clip_image001[6]

4.) Select "Change your Media/Language Type".clip_image001[8]

5.) Select the language of your choice:
clip_image001[10]

And no more hours of throwing away useless DVD - PLUS: you've helped reducing the wastage.

If you surprisingly need a language later on: No need to be confused - you can download it from the MSDN site anyway.

2 Comments
Filed under: ,

Last time we started by translating a LINQ query

List<int> ints = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8 };

var filteredInts = from i in ints where i > 5 select i;

into an extension method (as the C# compiler does in background):

var filteredInts = ints.Where(i => i > 5);

But where do we go from here? What is the strange => arrow doing within my method call?!
This is basically a different notation for an anonymous method.

Let's start with a default .NET 2.0 code doing a calculation with the use of anonymous methods.

        delegate int CalcDelegate(int a, int b);

        static void Main(string[] args)
        {
            CalcDelegate add = delegate(int a, int b)
            {
                return a + b;
            };
            var result = add(10, 5); // 15
        }

With C# 3.0 we could change this code into the new notion of a lambda expression:

            CalcDelegate add = (a, b) =>
            { // Statement Body
                return a + b;
            };
            var result = add(10, 5); // 15

The => arrow indicates a lambda expression. This expression has a statement body - meaning it has curly brackets and some C# code within. You can skip the delegate keyword, the types of a and b will automatically be inferred regarding the signature of the delegate.

You could do anything within the statement body, like:

            CalcDelegate add = (a, b) =>
            {
                Console.WriteLine("Hello World");
                ...
                return a + b;
            };

If you only have a return statement within your expression's body, you can also switch to an "expression body" (instead of statement body).

The lambda expressions then look like this:

CalcDelegate add = (a, b) => a + b; // Expression Body

The return statement and the curly brackets are then removed.

If you disassemble the lambda expressions (either with statement or with expression body) you'll find out, that the compiler generates an anonymous method out of the expression automatically in background.image

With the expression body you can basically use every statement which returns a type similar to the return value-type of the delegate.

Instead of creating your own delegate type, you can use a predefined generic delegate called Func. This delegate takes one return type and up to four parameter types. To get the same delegate as our custom CalcDelegate you could use:

Func<int, int, int> add = ...;
Func<string, int, bool> check = (text, length) => text.Length == length;

The second method checks, whether a passed string's (first parameter "text") length matches a passed int (second parameter length). The result is returned as boolean.

What, if you want to analyze a lambda expression to transform it into a SQL query for instance? You could use reflection of course to go over the code of the generated anonymous method, but this is rather difficult.

So for lambda expressions with an expression body (like the one above) there is a special notation called expression trees.

If you specify

Expression<Func<int, int, int>> addExp = (a, b) => a + b;

this is going to be changed into an expression tree of some delegate in background:

      ParameterExpression par1;
      ParameterExpression par2;
      Expression<Func<int, int, int>> addExp = Expression.Lambda<Func<int, int, int>>(
         Expression.Add(
            par1 = Expression.Parameter(typeof(int), "a"),
            par2 = Expression.Parameter(typeof(int), "b")
         ), par1, par2);

What you get is logical view of your lambda expression (called tree), which you can then analyze by using it's Body property.

If you want to execute the expression tree later as a delegate , you need to compile it to source code by calling:

     Func<int, int, int> addDel = addExp.Compile();
     var result = addDel(1, 2);  // 3

So when you specify a lambda expression (with an expression body), the compiler will either produce an anonymous method, or an expression tree out of it, depending on what the target type requires (if it is a delegate or Expression<delegate>).

In my opinion this is pretty neat!

While LINQ-To-XML and LINQ-To-Objects use Func<T..> as parameter, LINQ-To-SQL uses Expression<Func<T..>>, so that the tree can be translated into a SQL Statement.

More Posts Next page »
 
Page view tracker