1) DomainContext class changed significantly

One of improvements is adding support for Asynchronous Domain Operations. DomainContext supports three kinds of domain operations : Query, Submit and Invoke .

I have example where I call Load method of DomainContext and the asynchronous Load call returns a LoadOperation instance immediately or you can add your custom code on load completed:

 LoadOperation<Customers> load=this.context.Load(this.context.GetCustomersQuery());

          load.Completed += new EventHandler(load_Completed);

          this.dgGrid.ItemsSource = load.Entities;

 

2) DomainDataSource API Changes

Don’t break designer anymore. Minor paging problems are also solved.

Previously :

_domainDataSource.LoadMethodName = "GetCustomers";

 _domainDataSource.LoadParameters =new System.Windows.Data.ParameterCollection();

Now :

_domainDataSource.QueryName = "GetCustomers";

 _domainDataSource.QueryParameters =new System.Windows.Data.ParameterCollection();

 

Silverlight 3 databinding improvements with ElementName allows developers to bind one UIElement to another in XAML instead of having to write event handlers.

So now I bind DomainDataSource with my DataPager like this :

 Source="{Binding Data, ElementName=_domainDataSource}"

 I have attached some demo project bellow to show this.

 

3) New project type called .NET RIA Services Class Library

This project is used to simplify creation of N-Tier RIA services applications.

Picture1

When you choose to create .NET RIA Services Class Library it generates to class library projects

one for server and and for client side. Client side middle tier project you reference from your Silverlight app and server side middle tier you reference from your server side project. Project structure looks like this :

Picture2

 

When you add Entity context and DomainContext to .NET RIA Services Class Library project for server side and build project, MS Build will generate client side proxy for you in generated code folder on client side class library project.

Advantages of  middle tier class libraries are that they can be reused in other applications but shared code (specifically *.shared.cs ) in the class libraries is not propagated to the silverlight client during code generation.

 

4) No more need for add [Shared] metadata attribute

and much more changes….

Demo for paging with new DomainDataSource looks like this :

 


RiaServicesPagingDemo.rar

Be the first to rate this post

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

Launch event Silverlight 3 and Expression

Published 10.07.2009 04:59 AM by Admin in Silverlight

Watch http://www.seethelight.com/ for launch of Silverlight 3 RTW and Expression Blend 3 RC.

For download infomation about Silverlight 3 and Blend visit :

http://geekswithblogs.net/tkokke/archive/2009/07/09/silverlight-3-downloads.aspx

Be the first to rate this post

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

If you are interesting to learn more about Validation Application Block you can always download Hand on Labs about VAB: http://www.microsoft.com/downloads/details.aspx?FamilyID=2C34A9CB-17CF-4AEC-8DE6-EEACBBB74413&displaylang=en

In these labs you will find very good explanation about using VAB integration with WCF, but what if you are manually creating proxy instead using add service reference?

In this article I will show you how to use VAB 4.1 with WCF and manually generated proxy.

My solution structure looks like this :

Picture1

I have created one project called DataContracts where all DataContract classes and Validation rules are defined. Code for that class looks like this :

 public class Customer

    {

        [StringLengthValidator(1, 25,

           MessageTemplateResourceType = typeof(Resources),

           MessageTemplateResourceName = "FirstNameMessage")]

        [NotNullValidator]

        public string FirstName { get; set; }

        [StringLengthValidator(1, 25,

          MessageTemplateResourceType = typeof(Resources),

          MessageTemplateResourceName = "LastNameMessage")]

        [NotNullValidator]

        public string LastName { get; set; }

        public string Nickname { get; set; }

        public DateTime BirthDate { get; set; }

        [ObjectValidator]

        public Address Address { get; set; }

 

        public Customer()

        {

            this.Address=new Address();

        }

    }

 

    public class Address

    {

        [StringLengthValidator(1, 50)]

        public string StreetName { get; set; }

 

        public int Number { get; set; }

        [DomainValidator("AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA", "GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY",

            MessageTemplate = "Value is not a valid US state two-letter abbreviation.")]

        public string USState { get; set; }

 

    }

I have manually created proxy class. It looks like this :

  public class CustomerClientProxy : ClientBase<ICustomerService>, ICustomerService

    {

 

        public string ProcessCustomer(DataContracts.Customer customer, string notes)

        {

            return Channel.ProcessCustomer(customer, notes);

        }

 

    }

In service contracts project I have defined interface that WCF will use. We must decorate method signature in interface with  validation attribute that define FaultContract for method.

We are using  ValidationFault class that is defined in VAB for error transporting to the client side.

  [FaultContract(typeof(ValidationFault))]

        string ProcessCustomer(

            Customer customer, [StringLengthValidator(1, 100,

                MessageTemplate = "The notes must be 1 to 100 characters long.")]

            string notes);

In web config file for WCF service we must add new behaviorConfiguration for Endpoint. ValidationElement is used to perform some validation actions on WCF before calling method on WCF.

<behaviorExtensions>
<add name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF.ValidationElement, 
        Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF, Version=4.1.0.0, Culture=neutral, 
        PublicKeyToken=31bf3856ad364e35" />
</behaviorExtensions>

On client side I have one standard WPF application with basic App.Config where is just defined ABC for WCF. (address, binding, contract)

I have bind client side textboxes on the form with my Customer class.  After that I have some code to catch exceptions throw by the server and show that exceptions in simple message box.

using (Proxy.CustomerClientProxy client = new Proxy.CustomerClientProxy())

            {

                try

                {

 

                    Customer cust=((Customer)this.DataContext);

 

                    client.ProcessCustomer(cust, "My message!!!");

                }

                catch (FaultException<ValidationFault> fex)

                {

                    StringBuilder builder = new StringBuilder();

                    builder.AppendLine("Validation error invoking service:
"
);

                    foreach (ValidationDetail result in fex.Detail.Details)

                    {

                        builder.AppendLine(

                            string.Format("{0}: {1}
"
, result.Key, result.Message));

                    }

 

                    MessageBox.Show(builder.ToString());

 

                }

 

                catch (Exception ex)

                {

                    MessageBox.Show(ex.StackTrace.ToString());

                }

            }

After I run my application and enter some incorrect values I get message box :

Picture2

 

Here is complete code :ValidationServiceWCF.rar

Reference : http://www.clariusconsulting.net/blogs/kzu/archive/2007/09/24/WhyweneedanEntLibStandaloneValidationApplicationBlock.aspx

Currently rated 4.5 by 2 people

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

Radenko Zec Blog

Silverlight, C#, WCF, WPF,NET...