U2U Blog

for developers and other creative minds

U2U Beta Days

Be ahead of the game by coming to the U2U Beta days on 1 and 2 july 2009. On these 2 days we will cover the newest technologies of microsoft:

  • Windows 7
  • Azure
  • Visual Studio 2010
  • C# 4.0
  • Exchange and SharePoint online
  • Silverlight 3

These sessions are delivered by the U2U trainers who are already working on these technologies and eagerly waiting to talk about our experiences in the technologies.

Hope to see you in july

K.

The new BESUG site is released

Go and visit the new besug site. Become a member and attend our future Silverlight sessions, if you are already a member, SPREAD THE WORD :-)

 

besugsite

Upcoming:

  • Silverlight 3.0 workshop ( all seats are taken, but send me an email, and if somebody falls of, I let you know)
  • .NET RIA Services

K

Silverlight and Search crawling some tips

Very often people ask if search engines crawl silverlight sites. The answer is yes and no :-).  Yes, they crawl the webpage where the silverlight control is hosted, no they do not enter the silverlight control.

The problem is that Silverlight and other Rich Internet Application technologies load data dynamically, which is off course great for the visitor but a problem for search robots who only know how to read static data (like HTML).

So here are some options:

1. Add static information to the webpage where the silverlight control is hosted:

image

TIP: place just under the body tag

Now, when we write it like this are users will off course see the text, so we have to throw a little JavaScript to it and css to it.

image

or write it shorter with:

image

Imaging that the data is coming from a database off course :-). You could off course use AJAX to load the data in the hidden tags.

2. It is maybe a thought ( so never tried it ), but maybe you could place the content under the silverlight  control by using z-index in css.

3. Use the browser integration to get Silverlight content from the control and show it in the page.

4. Because Silverlight is an XML language you can also use XSLT to get the xaml you want and show it your page as static text

 

Basically, it all comes back to the same thing, change the dynamic data in static data and your Silverlight application will end up higher in the search results.

K.

Debugging out of the browser Silverlight 3 applications

In Silverlight 3 you have the option to create out of the browser applications. You can read more here or see more here.

At the Microsoft UXV days at Vitra, I had the question if it was possible to debug these out of browser applications. Off course the answer was yes, the only thing that you have to know is that the out of browser application is started by the sllauncher.exe of Silverlight. You can find this one in the Silverlight folder in the Program Files:

image

So when you are in Visual Studio, you can attach to this process ( in the debug menu of visual studio) and start placing breakpoints in you code:

image

K.

IErrorHandler: A generic Fault Converter (1/2)

In WCF, methods communicate error information by means of SOAP faults. These SOAP faults are message types which are part of the metadata of your service contracts:  service operations declare the possible faults by using FaultContracts.

[ServiceContract] 
public interface IOrderMgrService 
{ 
    [OperationContract] 
    [FaultContract(typeof(Faulty))] 
    string GetData(int value); 
} 

[DataContract] 
public class Faulty 
{ 
    [DataMember] 
    public string ErrorMessage { get; set; } 
}

 

In .NET applications, errors are represented by Exception objects. So, to travel the exception from the server to the client, one needs to map Exception objects to SOAP faults.

The problem with this approach is of course : how do you map exceptions to faults. You are probably going to define multiple FaultContracts which you need to define on all the operation contracts. So first, every operation will contain a big try…catch statement to map existing .NET exceptions into faults. And secondly, an operation can only expose those faults that are applied in the contract.

public string GetData(int value) 
{ 
    try 
    { 
        int divider = 0; 
        int restult = value / divider; 
    } 
    catch (DivideByZeroException ex) 
    { 
        throw new FaultException<Faulty>(new Faulty() { ErrorMessage = ex.Message }, 
            "GetData failed"); 
    } 

    return string.Format("You entered: {0}", value); 
}
 

A generic solution for this is implementing an ErrorHandler: create a class that implements IErrorHandler and implement both HandleError and ProvideFault.

The ProvideFault() method is called by any exception - a CLR exception or a fault -  that occurs in your operation. The error property contains the exception that occurred, the fault property will contain a fault if the exception is already converted into a fault (so you can check wethether it is null or not).

HandleError() takes the exception : this is execute on a seperate thread. Definitely the right place to add logging or tracing.

public class MyErrorHandler : IErrorHandler 
{ 
    public bool HandleError(Exception error) 
    { 
        return false; 
    } 

    public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault) 
    { 
       if (fault != null) 
           return; 

       if (error.GetType()== typeof(DivideByZeroException)) 
       { 
           FaultException<Faulty> f = new FaultException<Faulty>(new Faulty() { ErrorMessage = error.Message }, 
               "GetData failed"); 

           fault = Message.CreateMessage( 
                   version, 
                   f.CreateMessageFault(), 
                   f.Action); 
       } 
    }
    ...
 

An ErrorHandler is installed as a ServiceBehavior by registering it per ChannelDispatcher. The easiest way is to make your ErrorHander class an attribute and implement the IServiceBehavior interface on it.

public class MyErrorHandler : Attribute, IErrorHandler, IServiceBehavior 
{
   ...
 

The ApplyDispatchBehavior method passes a reference to the service host, which you can use to iterate over the different ChannelDispatchers in order to add your ErrorHander to the ErrorHandlers collection.

public void ApplyDispatchBehavior(ServiceDescription serviceDescription, 
  System.ServiceModel.ServiceHostBase serviceHostBase) 
{ 
  foreach (ChannelDispatcher disp in serviceHostBase.ChannelDispatchers) 
  { 
    disp.ErrorHandlers.Add(this); 
  } 
}

Silverlight in SharePoint

Sorry for posting this late, but here is the slide-deck and the code that Karine and I showed during the BESUG presentation at the Microsoft buildings.

Keep an eye on the BESUG site for upcoming events. Next meet up will be at the community days where we will present Silverlight 3