DCSIMG
September 2006 - Posts - Guy Burstein's Blog

Guy Burstein's Blog

Developer Evangelist @ Microsoft

News

Guy Burstein The Bu

Disclaimer
Postings are provided 'As Is' with no warranties and confer no rights.

Guy Burstein LinkedIn Profile

TwitterCounter for @bursteg

September 2006 - Posts

.Net Framework 3.0 September CTP is here!

The September CTP of the Windows SDK and .NET Framework 3.0 are live on the web at these URLs:

Microsoft Windows SDK DVD ISO

.Net Framework 3.0 Runtime Components

Extensions for Windows Workflow Foundation Release Candidate 5 (Same as RC1)

Development Tools for .NET Framework 3.0

  

Enjoy!

Wanna play with Visual Studio "Orcas"?

September CTP of Visual Studio "Orcas" is available for download.

This CTP is provided as a Virtual PC Image, so if you want to give it a go you can download it from here.   You can get Virtual PC and Virtual Server for free from here (Virtual PC) and here (Virtual Server).

The highlights of this CTP include:

  • LINQ to Objects API (query arrays, generic lists and other .Net collections using LINQ)
  • Partial C# 3.0 support (see http://msdn.microsoft.com/netframework/futures) for more details on where this is going
  • .Net framework improvements

Enjoy!

[ADO.Net vNext] - Entity Data Model Designer CTP

The ADO.Net team has announced that a prototype of the visual designer for creation Entity Data Models is available for download.

The designer in this CTP is an early prototype and only supports designing the “Conceptual” layer. The designer can also generate an Entity Data Model with 1:1 mappings from an existing database that you can use right away in your application while also graphically visualizing the “Conceptual” layer.

Read more about the EDM Designer in the ADO.Net team Blog.

Enjoy!

ServiceFaultHandler - WCF ExceptionHandler for Enterprise Library

One of the projects I am currently working on, uses both Windows Communication Foundation and Enterprise Library 2.0. While there is no out-of-the-box integration between those two, we ran into some points where some work had to be done.

One of them is to create an exception handling policy for Enterprise Library that replaces an .net exception with a fault contract exception.

 

I'll take this post to go throw the need and the solution we came up for it.

So here goes…

 

WCF Fault Handling

When an exception occurs in a WCF service, the wire cuts off and the client receives a communication exception saying that a response was never received from the server.

If you want your client to receive exceptions from the server you can explicitly enable receiving exception details (using configuration) or declaring a Fault Contract. A Fault Contract is an attribute you place above a service operation, that means that the operation can return a fault of the a certain type. Examine this service contract:

 

[ServiceContract]

public interface IEchoService

{

    [OperationContract]

    [FaultContract(typeof(ServiceException))]

    void Echo(string message);

}

 

This definition of a service contacts means that the Echo operation can return Faults of type ServiceException. ServiceException can be any serializable class or any class decorated with DataContract attribute.

 

As an implementation for this operation, in order to return a Fault in the same model that we throw .net exceptions, you can use the following way:

 

public class EchoService : IEchoService

{

    #region IEchoService Members

    public void Echo(string message)

    {

        try

        {

            Console.WriteLine("Echo: " + message);

            throw new ApplicationException("Echo: " + message);

        }

        catch (Exception ex)

        {

            throw new FaultException<ServiceException>(new ServiceException(ex.Message));

        }

     }

    #endregion

}

 

In order to catch the exception in the client side, use this following code:

 

try

{

       // Call the Echo sevice       

}

catch (FaultException<ServiceException> ex)

{

    ServiceException sex = ex.Detail;

    Console.WriteLine(sex.GetType().FullName + "\n" + sex.Message);

}

 

Enterprise Library Exception Handling

To handle an exception when using Enterprise Library, you should configure a policy using the configuration file or tool.

A policy has its unique name, the exception types it applies to (similar to catch block) and the exception handlers. For each exception type you configure an action that should be done after all the handlers were executed. This post action can be None, ThrowNewException or NotifyRethrow.

To get more details about the configuration of exception handling policies, refer to the exception handling quickstart (ships with Enterprise Library), or to the Enterprise Library Hands-On Labs.

To handle an exception using a configured policy, use the following piece of code:

 

try

{

       // Your code here...

 

catch (Exception ex)

{

    if (ExceptionPolicy.HandleException(ex, "MyPolicy")) throw;

}

 

Creating a custom Exception Handler

There are few exception handlers that ship with Enterprise Library for example – ReplaceHandler that replaces the exception new exception and WrapHandler that wraps the exception with a new exception of a specified type.

To create a custom exception handler, you should simply create a class that inherits the IExceptionHandler interface:

 

public interface IExceptionHandler

{

    Exception HandleException(Exception exception, Guid handlingInstanceId);

}

 

While creating a custom exception handler is very easy and straight forward, creating what it takes to configure it is a bit more complicated, but rather interesting in my opinion. In general, one should create an custom Exception Handler Data class (that inherits from ExceptionHandlerData) that represents the configuration data for the custom handler. Additionally one should create and assembler , that instantiates the custom handler with the configuration data.

I think that the Enterprise Library Polymorphic configuration collection mechanism is a very interesting and useful infrastructure, and I can only advise the reader to explore more deeply into it.

 

Creating a Fault Exception

 

To use the ServiceFaultHandler you should configure it in the following way:

<exceptionHandlers>

  <add name="ServiceFaultHandler"

       type="Bursteg.Samples.ExceptionHandling.ServiceFaultHandler, Echo.Service"

       exceptionMessage="Service Fault Exception: The service operation threw an exception."

       detailsExceptionType=" Bursteg.Samples.ExceptionHandling.ServiceException, Echo.Interfaces"/>

</exceptionHandlers>

 

Notice that in addition to the name and type of the handler the configuration element takes the exception message and detailsExceptionType attributes. At runtime, the handler will create FaultException<T> where T is the detailsExceptionType supplied here. Notice that this exception type should also be declared in the FaultContractAttribute in the service contract.

 

The real interesting code which is the core implementation for this component can be found in the WrapException method in the ServiceFaultHandler class:

 

private Exception WrapException(Exception originalException, string detailsExceptionMessage)

{

    // Create the detail exception

    object[] extraParameters = new object[] { detailsExceptionMessage };

    Exception detail = (Exception)Activator.CreateInstance(DetailExceptionType, extraParameters);

 

    Type faultExceptionType = typeof(FaultException<>);

    Type faultBindedExceptionType = faultExceptionType.MakeGenericType(DetailExceptionType);

 

    // Create a meaningful fault reason

    FaultReason reason = new FaultReason(originalException.Message);

 

    // Construct a new fualtException with generic type

    extraParameters = new object[] { detail, reason };

    Exception detail2 = (Exception)Activator.CreateInstance(faultBindedExceptionType, extraParameters);

    return detail2;

}

 

The above code creates an instance of the exception that was defined in the configuration and in the FaultContract with the input error message.

Than the method create an instance of FaultException<T> where T is that detailed exception. Finally that exception is thrown back to the caller.

 

Hope you find this useful, I'd love to get any comments and questions for this post and sample.

 

You can download a sample project that demonstrates the ServiceFaultHalder.

 

Enjoy!

Plans for Enterprise Library v3

After getting through the Vision and Scope for the next release of Enterprise Library v3, the Patterns & Practices team has posted the list of features for the first milestone:

  • Medium Trust support
  • Manageability extensions for configuration (WMI, Group Policy)
  • Simple Strong-naming
  • Mini-Factory for building your own blocks and providers
  • Validation Application Block
  • Exception Handling: WCF integration (exception shielding / fault mapping)
  • Logging: WCF pipeline integration
  • AuthZ: WCF Pipeline integration

You can expect to see a bit more activity (and eventually some early code drops) on the Enterprise Library Community site.

 

Read more in Tom's Blog.

 

Enjoy!

VS2005 Tip: Nest files for partial classes

Partial classes are a great new feature in Visual Studio 2005. They allow the definition of a class, struct or interface to be split into multiple files.

You usually find partial classes when using some kind of a designer, such as Windows Forms Designer, or DataSet Designer, but sometimes you just want to split your class to separate files (maybe to allow some developers work simultaneously on the same file in source control).

 

In order to arrange the solution a little bit, Instead of keeping all files of the same partial class in the same tree level, you can nest them under a single file name, like the following example:

 

 

It turns out that there is no easy way for doing that from the Visual Studio IDE. But, If you follow these steps, you can do it on your own:

 

  • Create a new Console application. The solution opens with the project that contains a code file called Program.cs (of Program.vb)
  • Open the Program.cs file, and add the partial keyword before the class definition. Your class definition should look like:

     partial class Program

       {

           ...

  }

 

  • Add a new class to the project, call it Program.Extention.cs. (You can replace the .Extension with any other naming convention you have in your project).
  • Open the Program.Extention.cs file and notice that the class name is also Program. Add the partial keyword before the class definition.

And now for the real stuff:

  • Right click the header of the tab that displays the code for Program.cs and choose “Open Containing Folder”. This will open the folder in with the files are stored.
  • Notice that this folder also contains the .csproj file of your project. Open this file with a text editor (Notepad should do it..) and search for the following block:

    <Compile Include="Program.cs" />

    <Compile Include="Program.Extension.cs" />

 

  • Change this block to create the requested nesting to the following block:

    <Compile Include="Program.cs" />

    <Compile Include="Program.Extension.cs">

            <DependentUpon>Program.cs</DependentUpon>

    </Compile>

 

  • Save the file and return to Visual Studio. It will ask you to reload the project. When you do so, your files will be nested like the above example.

Enjoy!

New Year Trip to Jerusalem

Advantech arranged an evening trip to Jerusalem last week for celebrating the New Year! After travelling in the City of David, we had a great celebration in an ethnic resturant.

In this picture (From the left): Shai Brumer, Guy Burstein, Dan Amiga and Shahar Nechmad.

In this picture (From the left): Eyal Heiferman, Shai Brumer, Guy Burstein and Dan Amiga.

Cheers!

Updated WCF Documentation announced! (September 20th)

Download thw latest Documentation CTP of Windows Communication Foundation. This time it's 40Mb which is twice the size of the previous version.

This CTP is aligned with the .Net Framework 3.0 RC1 and contains more complete docs and all the SDK samples embedded into the documentation for download.

Enjoy!

WCF Live Service Trace Viewer - Beta 1

The Service Trace Viewer provided with the .NET 3.0 SDK allows the operation of Windows Communication Foundation applications to be examined after the fact. 

The Live Service Trace Viewer  by Craig McMurtry & Vittorio Bertocci shows the application services interaction while it’s happening

As such, it can serve as a tool for diagnostics and also to make any Windows Communication Foundation demonstration come alive. 

A video of the Live Service Trace Viewer in action can be found here.  The Channel 9 interview with Laurence Melliol and Craig is here.

Enjoy!

Web Client Software Factory project kicks off!

The patterns and practices team has just released their first community drop of the Web Client Software Factory (available at www.msdn.microsoft.com/webclientfactory)

The Web Client Software Factory is a guidance will provide comprehensive architecture guidance to help customers build web solutions using the Microsoft platform (ASP.NET, ASP.NET AJAX, Workflow Foundation, etc).

The factory will include:

  • Scenario documentation (a description of the requirements and technical challenges that the factory will address)
  • Architecture documentation
  • Design patterns
  • How-tos
  • Guidance Packages (Visual Studio 2005 extensions for automating common tasks)
  • Reference Implementations (complete sample applications using the Factory)
  • Training content (Hands-On-Labs, demos, etc)

Enjoy!

Windows Vista SideBar on your Windows XP

Today I ran into a package which makes Windows Vista Sidebar available on Windows XP.

You can find it here.

Enjoy!

WF MSDN Nuggets

As posted earlier, an MSDN Nugget is a webcast that takes you step-by-step to discovering new functionality or exploring a hot developer topic, all in 10-15 minutes.

If you're new to Windows Workflow Foundation or you just want to catch up with cool features, check out these nuggets:

01 - Hello World Workflow

02 - Dealing With Exceptions

03 - Conditional Logic

04 - The Conditioned Activity Group

05 - Working in Parallel

06 - Dealing With Cancellation

07 - Listening For Events

08 - Passing Parameters to Workflow

09 - Working with Transactions

10 - Communications from the Workflow to the Host

11 - Communications from the Host to the Workflow

12 - Bidirectional Communication (Host <> Workflow)

13 - State Machine Workflows

14 - Building a Simple Workflow Activity

15 - Building Declarative Workflows

16 - Modifying Workflows whilst Running

17 - Using a Persistence Service

18 - Building a Persistence Service

19 - Using a Tracking Service

20 - Building a Tracking Service

21 - Using a Scheduling Service

22 - Building a Scheduling Service

23 - Calling a Web Service from a Workflow

24 - Using the Synchronization Activity

25 - Calling Other Workflows

26 - Correlation

27 - Composite Activities

28 - Exposing Web Services

Enjoy!

.Net framework 3.0 Learning Guides

Great learning guides and resources sites for .Net 3.0 Technologies:

Windows Communication Foundation

Windows Workflow Foundation

Windows Presentation Foundation

Enjoy!

WCF One-Way Calls, Callbacks, And Events

Juval Lowy has published a new article in MSDN Magazine (October 2006) that deals with one-way operations, callback operations and many more important topics in building distributed applications using WCF. The article also discusses the Publish-Subscribe Framework, and Event Publishing. This can be very useful when designing a message bus component.

Read it here.

Enjoy!

Community Server 3.0, Codename "Calypso"

After shipping version 2.1 of Community Server this August, the team has already started working on version 3.0, code name "Calypso".

Main features in the 3.0 release are:

  • A new Theme Engine.
  • Better membership management.
  • Centralized File Storage System and
  • Mail Gateway.

Hope I get the change to see some early bits soon...

Read more about the new release here...

More Posts Next page »