Featured, General, RealDolmen, Headline »

[15 Dec 2011 | 1 Comments]

It’s been an interesting year, but quite a morbid one as well apparently: a lot of technologies, frameworks & principles have been declared dead, if you want to believe everything you read. Silverlight? Dead. Flash/Flex? Dead. Java? Dead by standstill and fighting. ASP .NET Webforms? Dead. .NET, even? Dead – WinRT to the rescue. And apparently Biztalk has been dead for years.

 

Well have you ever!

 

Today it came to my attention that it doesn’t stop there:

 

Conclusion? Well, apparently, the internet is full of crap. Of course, none of what I mentioned above is dead. If anything, we’ve never had a demand as high as this year for Silverlight & Flex, and mobile Apps in general (note: at the company I work for, we mainly build business app – your opinions may vary ;-)). Some of the stuff that’s been declared dead (HTML5) hasn’t even matured yet: demand is only going to go up, not down, the next few years.

 

In other words: when you’re reading yet another article on the imminent dead of a certain technology, take it with a grain of salt. If something is declared “dead”, the author probably means he or she thinks (or hopes) it will be “dead” in 3 to 5 years or so. Take a look at predictions that were made 5 years ago, and you immediately know the value (or lack of value) of these predictions.

 

Dead? Not really.  

.NET, Featured, RIA, Headline, WCF RIA Services »

[6 Dec 2011 | 0 Comments]

WCF RIA Services Contrib is an open-source CodePlex project, maintained by Colin Blair, which consists of a collection of community contributions that can be used with WCF RIA Services.  At the moment, it consists of ComboBoxExtensions, a Data Validation Framework, Entity Tools, Entity Graph, Fluent Metadata API & T4RIA – you can find more info on those here.

 

Recently, I contributed a bunch of extension methods to the Entity Tools component.  These are methods I tend to use in projects, so I figured: why not release them to the community? :)

 

An overview:

 

  • public static IEnumerable YieldChildEntities(this Entity parent, EntityChangeSet changeSet,
    bool includeDirectChildrenOfEntityBaseType = false)
  • public static IEnumerable YieldChildEntities(this Entity parent, EntityContainer container,
    bool includeDirectChildrenOfEntityBaseType = false)
  • public static void DeleteChildEntities(this Entity parent, EntityContainer container,
    bool includeDirectChildrenOfEntityBaseType = false)
  • public static void DetachChildEntities(this Entity parent, EntityContainer container,
    bool includeDirectChildrenOfEntityBaseType = false)
  • public static void RejectChangesOnChildEntities(this Entity parent, EntityContainer container,
    bool includeDirectChildrenOfEntityBaseType = false)
  • public static void RejectChangesOnChildEntities(this Entity parent, EntityChangeSet changeSet,
    bool includeDirectChildrenOfEntityBaseType = false)
  • public static void AttachRange<T>(this EntitySet<T> entitySet, IEnumerable<T> entitiesToAttach) where T : Entity
  • public static IEnumerable<T> GetEntitiesOfType<T>(this EntityChangeSet changeSet, bool includeAddedEntites = true, bool includeModifiedEntities = true, bool includeDeletedEntities = false) where T : Entity
  • public static bool HasValidationErrors(this System.ServiceModel.DomainServices.Client.SubmitOperation submitOperation)
  • public static bool HasValidationErrors<T>(this System.ServiceModel.DomainServices.Client.SubmitOperation submitOperation) where T:Entity
  • public static IEnumerable<ValidationResult> GetAllValidationErrors(this System.ServiceModel.DomainServices.Client.SubmitOperation submitOperation)
  • public static IEnumerable<ValidationResult> GetAllValidationErrors<T>(this System.ServiceModel.DomainServices.Client.SubmitOperation submitOperation) where T:Entity

 

At the moment, the only way to access these is by downloading the source code, but in the (near) future, they will be included in the NuGet package for Entity Tools, so you might want to keep an eye on that. 

 

Enjoy! :)

.NET, Featured, Silverlight, Headline, WCF RIA Services »

[21 Nov 2011 | 0 Comments]

design-museum-extra-normal-clock-2009Sooner or later, you’ll run into this, if you haven’t already: the dreaded timeout error (or NotFound error), especially with long running operations or queries. The problem? Not all timeouts are the same (to quote a famous writer: all timeouts are created equal, but some timeouts are more equal than others). An error like that can come from your binding (which has a SendTimeout property), but it can also come from your data layer: there are timeouts that can be set on your SQL commands, and on your SQL connections.

 

Let’s look into the binding timeout first. We’re using WCF RIA Services, so you’ll need to gain access to the binding on your endpoint. This can easily be achieved through the OnCreated method of your DomainContext, as such:

 

public  partial class MyDomainContext
{
    partial void OnCreated()
    {
        PropertyInfo channelFactoryProperty = this.DomainClient.GetType()
                                                  .GetProperty("ChannelFactory");
        if (channelFactoryProperty == null)
        {
            throw new InvalidOperationException(
              "There is no 'ChannelFactory' property on the DomainClient.");
        }

        ChannelFactory factory = (ChannelFactory)channelFactoryProperty
                                 .GetValue(this.DomainClient, null);

        factory.Endpoint.Binding.SendTimeout = new TimeSpan(0, 10, 0); 
    }
}

 

With this code in place (you put this where the generated DomainContext code resides – make sure you use the correct namespace, this must reside in the same namespace as your DomainContext), the SendTimeout on your binding is now set to 10 minutes: this makes sure the request can now last 10 minutes. You might notice there are other timeouts you can set here as well: CloseTimeout, OpenTimeout and ReceiveTimeout, but: SendTimeout is the one that defines the interval for the operation to complete before a timeout error is thrown.

 

Next on the list: the command timeout. If you’re accessing a database in your domain operation, this can timeout as well: the command timeout is what defines the maximum amount of time that’s given to the command to execute the provided SQL code (default: 60 seconds). For long running queries on your database, you will need to change this. We’re using WCF RIA Services, and let’s assume we’re also using the Entity Framework: on your DomainService, there’s an overrideable method, CreateObjectContext. This is where you can define the command timeout, as such:

 

protected override MyEntities CreateObjectContext()
{
    var objectContext = base.CreateObjectContext();
    objectContext.CommandTimeout = 1200;
    return objectContext;
}

 

And on the the last one: connection timeout. This is the time you allow to open a connection to your database. Typically, this should be small: if it takes more than, say, a minute to open your connection, you know something is seriously wrong. But if you want to change this (the default is 15 seconds), you can do it via the connection string:

 

Data Source=(local);Initial Catalog=AdventureWorks;
Integrated Security=SSPI;Connection Timeout=30

 

If you keep these 3 timeout values in mind, timeouts for (long running) operations should be a thing of the past.

 

Oh, one more thing: if you’re working with authentication, and your require authenticated access to your services, the authentication ticket could time out as well (you can define this value yourself), resulting in an Access Denied error. To avoid this, using sliding expiration (true by default) will already help a lot (and is a good practice for most applications). Next to that, make sure you correctly catch & handle errors of this type, by asking the user to log in again when his authentication ticket has expired. This is how this could look in your web.config file:

 

<authentication mode="Forms">
  <forms slidingExpiration="true" timeout="180"/>
</authentication>



Happy coding! :-)

General, Silverlight »

[8 Nov 2011 | 0 Comments]

As some of you might know, this blog isn’t the only place where I publish content: I regularly write articles that get published on other sites (and which I obviously can’t just duplicate on this blog, although I try to think about posting the links in an update), and some content is published as books or e-books as well.

 

As it was becoming increasingly difficult to keep an overview of what got posted where, I decided to add 2 pages to this blog: one outlining the content that’s published as a book or e-book, another one with a listing of articles, podcasts, … on other sites

 

I added these as an easy reference for myself (from time to time, I need to get organized ;-)), but as they might prove useful for you as well: a quick blog post. 

 

Enjoy! :-)

Silverlight, WCF RIA Services, Featured »

[4 Nov 2011 | 0 Comments]

When you’re working with WCF RIA Services, there are various ways to handle your validation: you can use the built-in data annotations, you can write custom validators on property level, on entity level, you can do cross-field validation, … and sometimes, you’ll need information in your validators that isn’t related to your Entity.  For example: your validation rule could be different depending on the role of the logged in user, depending on the location he’s at, …

 

For scenarios like this, you can use the ValidationContext: you can pass in a Dictionary<object, object> containing any state information you might need to ensure your validation rule works as expected.  For more information on this, you can find a great explanation at Jeff Handley’s blog.

 

That said, when you’re working with this, you might notice something strange when you put breakpoints in your validator: even though you’re passing in the correct state information through the ValidationContext, sometimes the Items collection might seem empty (just have a look around the internet, and you’ll notice quite a few people ran into this problem).  When someone mentions this problem, they’re typically using controls like a DataForm or DataGrid.  So, why is this?

 

Well: validation can be triggered at different moments, and by different controls.  Take a DataGrid for example: it triggers its own validation (for example: when you start editing a property). But the DataGrid control doesn’t have any knowledge of WCF RIA Services (Jeff also mentions this in his posts: you can never assume your validator will have access to the Items collection!). So: when validation is triggered by the DataGrid, it will execute the validators without the custom ValidationContext – therefore, the Items collection is empty (the same applies to services you provide) in those cases.

 

Luckily, validation is also triggered in the property setters (amongst other places), which does provide the correct ValidationContext, ensuring our validator works as expected.

.NET, Silverlight, Headline, WCF RIA Services »

[18 Oct 2011 | 0 Comments]

imageA quick heads-up: my 2-part article series on authorized navigation in Silverlight has been published at SilverlightShow

 

The first article tackles authorized navigation: allowing or refusing access to a certain page/View in your Silverlight application depending on the role of the user.

The second article concerns authorizing access to certain UI elements IN a View (instead of the complete View), depending on the role of the logged in user, and deciding what to do when the user hasn’t got the correct role (eg: do you want to disable the element, or do you want to hide it completely?).


The complete source code is included in both articles.

 

Update: a third part has been released, focussing on securing your service calls.


Happy coding! :-)

Silverlight »

[27 Sep 2011 | 0 Comments]

My publisher, Packt Publishing, is running a campaign at the moment in which you get 20% of each Silverlight book, 30% even if you order the e-Book version! 

 

So, if you were looking to learn some Silverlight, or enhance your skills, this might be the perfect time.  The campaign runs ‘till the end of September, and you can find all the details here.

 

(and of course, my Silverlight book is included in the deal as well ;-))