Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Using Microsoft .NET in WebSphere Message Broker V8: Part 4: Using the .NETCompute node for exception handling

Ben Thompson (bthomps@uk.ibm.com), Consulting IT Specialist, IBM
Author photo
Ben Thompson is a Consulting IT Specialist working on the WebSphere Message Broker development team at the IBM Hursley Software Lab in the UK. He is currently working on the design and implementation of .NET support in Message Broker. In the past, he has worked for IBM Software Services for WebSphere designing and implementing WebSphere solutions for IBM customers worldwide. You can contact Ben at bthomps@uk.ibm.com.
(An IBM developerWorks Contributing Author)
Matthew Golby-Kirk (mgk@uk.ibm.com), Software Developer, IBM
Matthew Golby-Kirk photo
Matthew Golby-Kirk is a software developer working on the WebSphere Message Broker development team at the IBM Hursley Software Lab in the UK. He works on the design and implementation of the HTTP and Web services support, along with the ESQL language run time in WebSphere Message Broker. You can contact Matthew at mgk@uk.ibm.com.

Summary:  This series of four tutorials demonstrates the new support for Microsoft .NET in WebSphere Message Broker V8. Part 4 shows you how to use the .NETCompute node for exception handling, using a scenario that builds in complexity as additional exception conditions are deliberately produced and then handled. Readers should be familiar with either Microsoft .NET or WebSphere Message Broker, but need not be familiar with both.

View more content in this series

Date:  22 Feb 2012
Level:  Intermediate

Comments:  

Using a .NETCompute node to handle a WebSphere Message Broker exception

  1. Amend the message flow MyFlow that you have been working with in the previous sections of the tutorial to include a .NETCompute node after the Trace node by dragging it from the Transformation drawer of the palette . The .NETCompute node API provides some methods that can interpret Message Broker exceptions, so that if you want to compose an exception for your own purposes, you can easily do so. Wire the Out terminal of the .NETCompute node to the In terminal of an MQ Output node by dragging it from the WebSphere MQ drawer of the palette. Rename the MQ Output node DOTNET.EXCEPTIONS.CATCH and set its Queue name property to the same value:

    MQ Output node Basic Properties
  2. Save the message flow, which should now look like this:

    MyFlow with .NETCompute node added

    Double-click the .NETCompute node, or right-click on it and select Open Microsoft Visual Studio.
  3. When Microsoft Visual Studio is launched, you will see the Start Page. Select New Project, as shown below:

    Microsoft Visual Studio Start Page
  4. Microsoft Visual Studio template extensions

    If the WebSphere Message Broker Toolkit is installed after Microsoft Visual Studio, then the broker's project templates will be automatically installed ready for you to use. However, if the Broker Toolkit is installed first, then you will need to manually install the templates by executing the file IBM.Broker.DotNet.vsix and stepping through the wizard. If you have used the default installation location, then you will find this file at C:\Program Files (x86)\IBM\WMBT800\wmbt.

    The New Project wizard provides three types of project templates in the Message Broker category. Select Project to create a Message Broker message. Specify the properties at the bottom of the New Project wizard, as listed beneath the image below, and Click OK:

    New Project wizard

    Name = ExceptionsDotNetProject
    Location = C:\student\DOTNET\lab_exceptions\visual studio 2010\Projects
    Solution Name = ExceptionsDotNetProject
  5. After the project is created, expand the Solution Explorer view. You should see that the CreateNode.cs file has been created to contain the C# class, and a reference to IBM.Broker.Plugin has been added. This assembly contains the helper methods from Message Broker to transform messages in a .NETCompute node:

    Solution Explorer references
  6. Locate the UserCode region of the CreateNode.cs file:

    UserCode region of CreateNode.cs
  7. Add the C# code in the listing below to the UserCode region:

    Listing 3. UserCode region demonstrating method CreateExceptionFromExceptionList:
    
    #region UserCode
    // Add user code in this region to create a new output message
    NBMessage inboundExceptionList = inputAssembly.ExceptionList;
    NBException exc = CreateExceptionFromExceptionList(inboundExceptionList);
    String pleasantExceptionMessage = exc.FormattedMessage(false); 
    NBElement outputXMLNSC = 
        outputRoot.CreateLastChildUsingNewParser(NBParsers.XMLNSC.ParserName);
    NBElement field = outputXMLNSC.CreateFirstChild("Message").CreateFirstChild("Field");
    field.CreateFirstChild(NBParsers.XMLNSC.AsIsElementContent, 
            "", pleasantExceptionMessage);
    #endregion UserCode
    

    XML development note

    The NBElement in the logical tree that holds the formatted message as a string value is assigned an XMLNSC type called AsIsElementContent. When the output node uses the XMLNSC writer to serialise the logical tree and convert it to an output message bitstream, it informs the writer not to carry out XML entity substitution. This technique makes the output readable and avoids XML entities in the output message. This should only be necessary in situations where you are trying to include XML reserved characters within the output of an XML message. The example includes this because it is the easiest way to render the error message with apostrophes in its text as readable XML output.

    The above code begins by navigating to the ExceptionList structure, which you have already examined using the Trace node, and which is passed into the .NETCompute node as part of the Input Message Assembly (logical tree hierarchy). The method CreateExceptionFromExceptionList converts the hierarchical ExceptionList tree structure into an NBException object, which provides a method named FormattedMessage, which re-inflates the object into a readable exception in which all message inserts have been reinserted. In the example, this nicely formatted message is then copied into the output message structure by the .NETCompute node.
  8. With the Visual Studio development work complete, the next step is to build an assembly file that you will reference from the .NETCompute node. From Solution Explorer, right click on the Solution and select Build Solution: Build ExceptionsDotNetProject

    How to open the Output window in Microsoft Visual Studio

    If the Output window is not visible in Microsoft Visual Studio Professional Edition, select Debug => Windows => Output. If the Output window is not visible in Microsoft Visual Studio Express Edition, select View => Output.

  9. The Output window will show you where the built assembly file has been saved on your file system. Depending on how you have Microsoft Visual Studio configured, the Build Output window may not be visible -- if it is not, follow the instructions in the sidebar. Build Output
    If you have used the default naming suggested throughout the tutorial, the assembly file should have been saved at:
    C:\student\DOTNET\lab_exceptions\visual studio 2010\Projects\ExceptionsDotNetProject\
    ExceptionsDotNetProject\bin\Debug\ExceptionsDotNetProject.dll
    

    Copy this location, as you will use it to configure the .NETCompute node in the next step.
  10. Return to WebSphere Message Broker Toolkit and configure the Assembly Name property of the .NETCompute node by pasting it from the previous instruction:

    Configure .NETCompute node
  11. Save the message flow: Type Ctrl-S or select File => Save.
  12. Return to the open test client file App_DotNet_Exceptions.mbtest, right click the Invoke Message Flow level in the hierarchy on the panel on the left, and select Re-run. The flow should be redeployed and the same message will be sent to the input queue again. This time, you should see an output message appear on the queue named DOTNET.EXCEPTIONS.CATCH:

    Result of Test 3
  13. Examine the output message and note in particular that the exception text should be nicely formatted in the Field element of the output XML message, which should look like this:

    Listing 4. Output message formatted using .NETCompute node method FormattedMessage
    
    <Message>
    <Field>( MB8BROKER.default ) Exception thrown by throw node 
    'DotNetExceptions.Throw'; text is 'This is a deliberate exception!'. 
    The throw node 'DotNetExceptions.Throw' has received a message and thus has thrown 
    an exception as this is its normal behavior.  The message text associated with this
    exception is 'This is a deliberate exception!'. Since this is application-generated
    (by message flow behavior), the user action is determined by the message flow 
    and the type of exception generated.</Field></Message>
    

4 of 10 | Previous | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=795296
TutorialTitle=Using Microsoft .NET in WebSphere Message Broker V8: Part 4: Using the .NETCompute node for exception handling
publish-date=02222012
author1-email=bthomps@uk.ibm.com
author1-email-cc=
author2-email=mgk@uk.ibm.com
author2-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).