This entry is just a summary about info I could find about BizTalk 2010.

Speculation about the release seems to be on 14/11/2010.

New set of posters and their details from the websites:

BizTalk Server 2010 BAM Poster

This poster provides an overview of the entire BAM life cycle. It depicts the design of the observation model by the business analyst, mapping the observation model to the implementation by the developer, deployment by the system administrator, and the presentation channels for business end users. Both new and experienced users will better understand the concepts, processes, and management of BAM. The poster is intended to be printed and measures 26”x28”.

BizTalk Server 2010 Runtime Architecture Poster

The poster depicts the modules and components of a BizTalk Server 2010 runtime environment, including message flow, data flow, and references that occur at runtime. It can be used to show how the capabilities listed in the BizTalk Server 2010 Capabilities Poster are actually implemented. The poster is intended to be printed and measures 35”x32”.

BizTalk Server 2010 Capabilities Poster

This poster lists the BizTalk Server 2010 capabilities bucketed in eight categories and is designed to enable technical discussions by providing both high-level and detailed views of the capabilities and features that are included. The poster has been updated to include new features and capabilities, including enhancements to RFID, BizTalk Adapter Pack, EDI, AS2, and better integration with Visual Studio and Windows Server. The poster is intended to be printed and measures 30.5”x28”.

BizTalk Server 2010 Scale-out Configurations Poster

This poster describes typical scenarios and commonly used options for scaling out BizTalk Server 2010 physical configurations. It illustrates how to scale out to achieve high availability through load balancing and fault tolerance and how to configure for high-throughput scenarios. The poster is intended for use by IT professionals and developers who need to design, deploy, and manage large-scale implementations of BizTalk Server 2010. The poster is intended to be printed and measures  26”x38”.

BizTalk Server 2010 ESB Toolkit Architecture Poster

This poster depicts the architecture of the BizTalk ESB Toolkit. It shows the toolkit's core components, and how these integrate with BizTalk Server. The poster is intended to be printed, and measures 26”x28”.

BizTalk Server 2010 Database Infrastructure Poster

This poster describes BizTalk Server 2010 databases and associated components, jobs, services, UI, and events. It includes tables that describe the databases and jobs. It is intended primarily for DBAs and administrators of a BizTalk Server environment, yet it also serves as an introduction to the infrastructure for all users. The poster is intended to be printed and measures 28”x30”.

Enjoy!

This entry is just an extension to the blog Memory Dump to the Rescue by Bruno Marques. In he’s blog he shows how to generate a mini dump on a exception in code. Please read he’s blog first. If you want to use this in ASP .Net MVC you could take the same approach:

  1: [HttpGet]
  2: public ActionResult Crash()
  3: {
  4:     try
  5:     {
  6:        // compiler doesn't allow division by a zero constant,
  7:        // so we have to use an auxiliary variable
  8:        int zero = 0;
  9:        int value = 123456789 / zero;
 10:     }
 11:     catch (Exception)
 12:     {
 13:        string path = Path.Combine(HttpRuntime.AppDomainAppPath, @"App_Data\Dumps\");
 14:        string fileName = string.Concat(path, Process.GetCurrentProcess().ProcessName, ".dmp");
 15:        MiniDump.WriteDump(fileName);
 16:     }
 17: 
 18:     return View();
 19: }

The first thing to note in the code is that I write the dump file to my App_Data folder under a sub folder named Dumps. This is a better approach for file and folder access rights in ASP .Net applications. I have a small issue with this approach. If I have to insert all this code to write a dump file in all my actions then my code will become very cluttered and maintenance of the code becomes difficult.


The Better Approach


All developers that have developed with ASP.Net MVC know of the Attribute [HandleError] that you can put on top of your controllers. With this we can create our own custom attribute to handle the error and create a mini dump file for the application.


Here is the custom attribute code:

  1: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
  2:  public class DumpHandleError : HandleErrorAttribute
  3:  {
  4:     public override void OnException(ExceptionContext filterContext)
  5:     {
  6:         string path = Path.Combine(HttpRuntime.AppDomainAppPath, @"App_Data\Dumps\");
  7:         string fileName = string.Concat(path, Process.GetCurrentProcess().ProcessName, ".dmp");
  8:         MiniDump.WriteDump(fileName);
  9: 
 10:         base.OnException(filterContext);
 11:     }
 12: }

Now I can cleanup my controller code as follow:

  1: namespace DumpMvcApplication.Controllers
  2: {
  3:     [DumpHandleError]
  4:     public class HomeController : Controller
  5:     {
  6:         [HttpGet]
  7:         public ActionResult Index()
  8:         {
  9:             ViewData["Message"] = "Welcome to ASP.NET MVC!";
 10: 
 11:             return View();
 12:         }
 13: 
 14:         [HttpGet]
 15:         public ActionResult Crash()
 16:         {
 17:             // compiler doesn't allow division by a zero constant,
 18:             // so we have to use an auxiliary variable
 19:             int zero = 0;
 20:             int value = 123456789 / zero;
 21: 
 22:             return View();
 23:         }
 24:     }
 25: }

All unhandled exceptions will be handled by my custom attribute to create a mini dump for the application.


Some additional tips is to create a abstract base controller with the attribute added and inherit other controllers from the base controller. Currently when the code creates a mini dump it will overwrite the dump file. If you want individual mini dumps for each exception I would recommend to add a DateTime.Now to the filename, but be aware that you have to cleanup your dumps else you might run out of disk space.


Hope this helps to ease your debugging experience for ASP .Net MVC applications.


Please comment and let me know on improvements that can be made to the code.


Cheerio!


I’m going to show you how to convert a raw WCF Soap Message to a Memory Stream.
Firstly here is the code:
1: [OperationContract(Action = "*")]
2: public void AddMessage(Message message)
3: {
4:   MessageBuffer buffer = message.CreateBufferedCopy(int.MaxValue);
5: 
6:   Stream stream = new MemoryStream();
7:   XmlWriterSettings settings = new XmlWriterSettings
8:                    {
9:                      Encoding = System.Text.Encoding.UTF8
10:                    };
11:   XmlWriter writer = XmlWriter.Create(stream, settings);
12: 
13:   //Create a copy of the message
14:   Message message = buffer.CreateMessage();
15: 
16:   //Serialize the message to the XmlWriter 
17:   if (writer != null)
18:   {
19:     message.WriteMessage(writer);
20:     writer.Flush();
21:   }
22: 
23:   stream.Flush();
24:   stream.Seek(0, SeekOrigin.Begin);
25: 
26:   // Save stream to database
27: }


The example above show a generic WCF method that accept any type of message. You might ask why do I ever want to do this? You might want to create a router service for your WCF services or you want to save a copy of a WCF message to a database. Working with an message stream provides allot of flexibility to work with the message contents.


Important points to note of the code is that I create a buffer copy of the original message. The reason is that the body of a message can only be accessed or written to once. If you want to access it more then once it is better to create a buffer copy of the message. From the buffer you can create multiple message instances. If you work with SOAP messages you need to specify the XmlWriterSettings Encoding to UTF8. Otherwise your stream data will become corrupt from the original message structure. Last note is when you create a stream to always flush and move the stream pointer to the beginning of the stream.


Hope this helps and any feedback is welcome.


Cheerio!

What a challenge I had to try and create unit tests for workflows that is hosted by WCF services. This challenges took me an month to investigate and solve.

So, here I will explain and give code to show you how to do proper unit testing. I'm going under the assumption that you do know how to hook up a Workflow with WCF service. Otherwise just follow the code in the example project and you will quickly get it.

This post will show the basics first and later I will provide more posts of how to write unit test for different scenarios with ReceiveActivity and SendActivity.

First off, I created a simple project to illustrate the scenario to create a client object and post it to a service that has a workflow. The workflow is very basic that it will receive the Client object message and save it to a database. I will just fake the actually writing to the database.

The project structure:

 

















Firstly we define the ServiceContract IClientService and hook it up to the workflow CreateClientWorkflow.xoml ReceiveActivity.



























Next I created a custom WorkflowServiceHostFactory that I will explain later in another post. I removed the code behind for the ClientService.svc and made the following changes.
   1: <%@ ServiceHost Service="ClientWorkflowLibrary.CreateClientWorkflow, ClientWorkflowLibrary, Version=1.0.0.0, Culture=neutral"
   2:                 Factory="CommonLibrary.WorkflowServiceHostFactory, CommonLibrary, Version=1.0.0.0, Culture=neutral"  %>
This basically show some of the key setup points. Now for the main topic namely the Unit Test. The one unit test is straight forward that you start you service and create a service reference and use a client proxy to communicate with the service, but that is more of an integration test. I will show know the correct way to test your workflow service.
The Proper Unit Test Code
   1: [TestMethod]
   2: [Description("Run Unit Test with Administrator privlidges. (VS in Administrator mode)")]
   3: public void CreateClientWorflow_ReceiveCreateClient_ReturnClientWidthValidGuid()
   4: {
   5:     // Arrange
   6:     Client requestClient = new Client
   7:                                {
   8:                                    Id = Guid.Empty,
   9:                                    Name = "User",
  10:                                    Surname = "Nobody"
  11:                                };
  12:     Client responseClient = null;
  13:  
  14:     // Setup WCF and WF
  15:     Uri baseAddress = new Uri("http://127.0.0.1:8999/UnitTestHosting");
  16:     WorkflowServiceHost host = new WorkflowServiceHost(typeof(CreateClientWorkflow), baseAddress);
  17:  
  18:     host.AddServiceEndpoint(typeof(IClientService), new WSHttpContextBinding(), "CreateClient");
  19:  
  20:     ServiceMetadataBehavior smb = new ServiceMetadataBehavior { HttpGetEnabled = true };
  21:     host.Description.Behaviors.Add(smb);
  22:  
  23:     // Add Custom Services to Workflow runtime
  24:     WorkflowRuntimeBehavior runtime = host.Description.Behaviors.Find();
  25:     runtime.WorkflowRuntime.AddService(new ClientRepository());
  26:  
  27:     // To enable Workflow Tracking and Persistence
  28:     //string connectionString = "Data Source=(local);Initial Catalog=Workflow;Integrated Security=true";
  29:     //runtime.WorkflowRuntime.AddService(new SqlTrackingService(connectionString));
  30:     //runtime.WorkflowRuntime.AddService(new SqlWorkflowPersistenceService(connectionString));
  31:     
  32:     // Act
  33:     try
  34:     {
  35:         host.Open();
  36:         EndpointAddress address = new EndpointAddress("http://127.0.0.1:8999/UnitTestHosting/CreateClient");
  37:         IClientService service = ChannelFactory.CreateChannel(new WSHttpContextBinding(), address);
  38:  
  39:         responseClient = service.CreateClient(requestClient);
  40:  
  41:         host.Close();
  42:     }
  43:     catch (Exception e)
  44:     {
  45:         Assert.Fail(string.Format("Error: {0}", e));
  46:     }
  47:     finally
  48:     {
  49:         if (host.State != CommunicationState.Closed)
  50:         {
  51:             host.Abort();
  52:         }
  53:     }
  54:  
  55:     // Assert
  56:     Assert.IsNotNull(responseClient);
  57:     Assert.AreNotEqual(Guid.Empty, responseClient.Id);
  58:     Assert.AreEqual(requestClient.Name, responseClient.Name);
  59:     Assert.AreEqual(requestClient.Surname, responseClient.Surname);
  60: }
To be able to run this code you need Administrator privileges. I follow the AAA syntax in unit testing. The Arrange part is where I setup my requestClient object and the WCF and Workflow configuration.

Firstly you setup the Uri address of where you want to host the service that will be dynamically get set as the unit test is run. Then you create the WorkflowServiceHost and assign the workflow that you want to test. Add an Service endpoint with the ServiceContact that is used in the workflow and the appropriate binding that should be used. Finally a name for the endpoint that you will call later to test.

You can add additional behaviour metadata. When you instantiate a WorkflowServiceHost then the WorkflowRuntimeBehaviour is automatically added. In the code I do a find on the host Behaviours to return the WorkflowRuntimeBehaviour instance. This instance is required to add additional custom service. For example the ClientRepository.You will see the code comment if you would like to add Tracking and Persistence to you workflow under test.

Now for the Act part. With WorkflowServiceHost setup we can open a connection to the service. I create a channel to the ServiceContract IClientService and assign the endpoint address that should be queried.
I call the relevant method on the ServiceContract and close the host connection afterwards. 
There is a catch and finally section to make sure that no exceptions was raised and that the host was properly closed.

The Assert part is at the end to separate the asserts from any communication problems. I specify multiple asserts just to show the variety of unit tests that could be written and should actually be written to different unit tests.

Hope you enjoy this post and any feedback or recommendation is welcome!

Cheerio!

Source: ClientService 1.zip

Today I just want to rant a bit about how lazy the average C# Visual Studio developer really is. This is just to show how a few simple 5 points can be done to improve code and the quality of code.

Point 1: Install GhostDoc

Get GhostDoc it is free! Install it and assign the relevant hot key and start documenting your code. Methods, Interfaces and Properties. Even if it is private. This tool generate the necessary documentation structure. You just have to do little fix ups here and there in the documentations sometime. Not difficult to use!

With all your code documented, it is easy to generate the relevant help file of your code and it helps in intellisense to describe what the method and parameters are used for. You should even list all the exceptions that might be raised by the method in you documentation.

This help the developer that might use your method to be alerted of a possible exception and he will know how to handle it.

Point 2: Get Reharper or other similar tool

Invest in yourself! Be the best you can by buying a tool like Resharper that helps you to refactor quickly and write cleaner code. Development is your lively hood so do the best job.

Point 3: Use StyleCop practices

Another free tool. Even if you don’t use the tool explicitly, just try to apply some of the guidelines it provides. Just following some of them will make your code more readable and cleaner again.

Point 4: Run FxCop

Wow, another free tool! Just run this tool before you check in and you might be surprised at what you need to do to make your code comply with the .Net coding guidelines. Again this tool helps you to improve your code.

Point 5: Code Clean-up

In general just follow good code clean up practices. Remove commented code that is not used. Order you properties, public and private methods together. Follow consistent naming convention.

One big pain point is when I see developers clean up after them self in production code, but not in the unit tests that they have written. Please take care of both!

No More Points

Just try using these 5 points and you are already on a road to be a better Visual Studio developer and more productive. I just want the standard of code for Visual Studio developers to be lifted, but that is allot to ask for.

There are a whole lot of other tools to use, but the tool listed above is a good starting point and does not take allot of time to learn.

Any questions of feedback is welcome!

Cheerio!




I’ve read lately three very interesting articles about “Why OK not to Write Unit Tests”, “Selective Unit Testing - Costs and Benefits” and “It’s Okay to Write Unit Tests”.

All these articles have valid points, but needs to be take into context of the overall development practices.

Here is my 2 cents and why developers like to be spoon fed. Since people have been born they had to be spoon fed in live, food and education. You can’t deny it! You always needed help.

Now this is where unit tests come into play with production code where they help the developer to be spoon fed to understand the API of the system. And YES it is necessary, because if someone new joined the project someone has to guide and explain to him how every little bit of the system works. That could take a couple of days.

I would rather tell the newcomer to look at the unit tests, play with them and you will understand the API and  processes of the system. Everyone likes code, otherwise you are not a developer and get out!

That is my 2 cents to the whole discussion going on between the relevant articles.

Until next time!

Cheerio!




Today I would just like to show how to correctly write the code when using a WCF client proxy to call an WCF service.

Firstly you have to create a Service Reference to the service so that the relevant code is generated for the client proxy.

Here is the correct code:
   1: ProductClient client = new ProductClient();
   2: try
   3: {             
   4:    client.Open();
   5:    client.UpdatePrice(10, 100.50);
   6:    client.Close();
   7: }
   8: catch (Exception e)
   9: {
  10:    Assert.Fail(e.Message);
  11: }
  12: finally
  13: {
  14:    if (client.State != CommunicationState.Closed)
  15:    {
  16:       client.Abort();
  17:    }
  18: }

As you can see I first create the ProductClient proxy object and call open. Then the relevant Web method and then close the client proxy channel.

Then I create a catch section to display the relevant details. In the code above I use Assert.Fail() because this code is used in a unit test, but you can but logging in or any other exception handling logic.

The finally section is there to check if the channel has closed successfully otherwise will call abort on the channel. This allows the correct exception details been catch if an exception is raised in the web method or when the channel is closed.

Here is the wrong code (The popular approach):

   1: using(ProductClient client = new ProductClient())
   2: {

   3:     client.UpdatePrice(10, 100.50);
   4: }


So what is wrong with this? Well the problem is that if an exception is raised in the web method UpdatePrice() and an exception is raised in the Close() method of the client proxy channel is closed by the using() statement then the close exception would hide the original exception that is raised by the web method UpdatePrice().

The first code snippet is much clearer and show what really is happening if an exception should be raised. Where the using does make the code smaller and handle the open closing of the client proxy, but could hide the specific details of the original exception.


Cheerio!

Disqus