BizTalk HotRod Issue7 Q3 2009

Embed Size (px)

Citation preview

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    1/79

    Page 1

    Issue 7 Q3 2009

    Table of ContentsPreface .......................................................................................................................................................... 3

    B2B 2.0 Azure a durable competitive advantage for Microsoft Take 2 ..................................................... 4

    EDI - continues to dominate B2B!........................................................................................................... 4

    B2B Adoption blockers are in fact opportunities for Microsoft............................................................. 5

    State of the technology.......................................................................................................................... 5

    B2B 2.0 with Azure the durable competitive advantage for Microsoft ............................................. 6

    Unit Testing Schemas and Maps in BizTalk Server 2009 A Different Approach! ...................................... 8

    Summary ................................................................................................................................................... 8

    Testing schema ......................................................................................................................................... 8

    Why is it Failing? ................................................................................................................................. 10

    How can it be Resolved? ..................................................................................................................... 10

    Now lets look at Map Files ..................................................................................................................... 12

    Why is it Failing? ................................................................................................................................. 13

    How can it be Resolved? ..................................................................................................................... 13

    Conclusion ............................................................................................................................................... 15

    Advantages with the above approaches ............................................................................................. 15

    Disadvantages with the above approaches ........................................................................................ 15

    Book Review for "SOA Patterns with BizTalk Server 2009" By Richard Seroter ......................................... 16

    How to Throw Typed Fault Exceptions from Orchestrations Published as WCF Services .......................... 18

    Typed Faults ............................................................................................................................................ 18

    Untyped Faults ........................................................................................................................................ 19

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    2/79

    Page 2

    BizTalk Orchestrations and Typed Faults ................................................................................................ 19

    The Solution ............................................................................................................................................ 22

    Proof of Concept in Action ...................................................................................................................... 35

    Show me the code! ................................................................................................................................. 35

    BizTalk Resources ........................................................................................................................................ 37

    BizTalk 24x7............................................................................................................................................. 37

    BizTalk Gurus .................... .......................... ......................... ...................... ........................... ................... 37

    BizTalk Server Customer Advisory Team ................................................................................................ 37

    Recently Released Documentation ......................................................................................................... 37

    BizTalk Server 2009 Install Documentation - June 2009 Update ........................................................ 37

    BizTalk Server 2009 Operations Guide - July 2009 ............................................................................. 37

    Microsoft Dynamics AX integration using Microsoft BizTalk Server ........................................................... 39

    Introduction ............................................................................................................................................ 39

    Configuring Microsoft Dynamics AX Adapter for BizTalk........................................................................ 41

    Terminology ........................................................................................................................................ 41

    Configuring Microsoft Dynamics AX Application Integration Framework (AIF) .............................. 42

    Send Data from BizTalk to Dynamics AX ............................................................................................. 54

    Receive Data from Dynamics AX in BizTalk ......................................................................................... 56

    Error Handling and Messages ............................................................................................................. 59

    Appendix A Configuring Message Properties for sending data to Microsoft Dynamics AX ................... 73

    Appendix B Related Documents/References .......................................................................................... 74

    Manage BizTalk Services Thru WMI Using C# .......................................................................................... 75

    Summary ................................................................................................................................................. 75

    Creating a WMI Managed Class for BizTalk ............................................................................................ 75

    Terminate Suspended Instances ............................................................................................................. 76

    Resume Suspended Instances ................................................................................................................. 78

    Advantages of WMI with C# approach ................................................................................................... 79

    Conclusion ............................................................................................................................................... 79

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    3/79

    Page 3

    Preface

    This issue has articles about Azure, BizTalk WCF Adapters, Book review, Unit Testing, Management with

    WMI and Dynamics AX Integration with BizTalk.

    BizTalk 2009 was released in May 2009. It was followed by ESB Toolkit 2.0. ESB Toolkit is now available

    to download fromhttp://www.microsoft.com/biztalk/en/us/esb-guidance.aspx . It is built on top of

    BizTalk 2009 and is a fully supported product. BizTalk Adapter Pack 2.0 was also released. In addition to

    enhancements to the existing adapters it contains new adapters for SQL Server and Oracle EBS.

    I want to thank Virtual TS Andy Morrison(Digineer) for helping with this issue. I also want to thank all the

    contributors for submitting their articles. If you have any suggestions for improvements or want to write

    in a future issue don't hesitate to contact me.

    Rajinder Singh

    [email protected]

    http://www.microsoft.com/biztalk/en/us/esb-guidance.aspxhttp://www.microsoft.com/biztalk/en/us/esb-guidance.aspxhttp://www.microsoft.com/biztalk/en/us/esb-guidance.aspxhttp://www.microsoft.com/biztalk/en/us/esb-guidance.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    4/79

    Page 4

    B2B 2.0 Azure a durable competitive advantage for Microsoft Take 2By Suren Machiraju, Principal Program Manager, Customer Experience Team, Microsoft

    Business-to-business (B2B) describes commerce transactions between businesses, such as

    between a manufacturer and a wholesaler, or between a hospital and an insurance

    company. Such transactions are expected to be generated and consumed by Line-of-

    Business applications with a high degree of automation and integration. Although the level

    of automation and processing of the B2B commerce has matured in industry segments

    dominated by mega- corporations such as financials (banking industry) and shipping (sea

    cargo and locomotive freight); and there are great many opportunities for establishing B2B

    commerce in supply chain and the Health Care industry verticals.

    EDI - continues to dominate B2B!The National Institute of Standards and Technology defines Electronic Data Interchange

    (EDI) as "the computer-to-computer interchange of strictly formatted messages that

    represent documents. The current volume of worldwide EDI transactions is more than 20

    million per day and accounts for a significant amount of worldwide commercial activity. In

    fact, some studies determined that more than one-third of the US GDP is directly supported

    by EDI transactions. The EDI market is estimated to be worth $3-$7 trillion. Some estimate

    that global EDI transactions are increasing between 5% and 10% per year.

    EDI transaction volume is expected to continue to grow in view of the adoption ofautomation strategies around the world to reduce cost of doing business; and politically

    driven investment initiatives e.g., in Health Care IT initiatives in American Recovery and

    Reinvestment Act of 2009.

    For the sake of completeness its worth mentioning here that there are other encoding

    standards (FinancialSWIFT; internet commerce/B2C-xCBL or cXML; Manufacturing-

    RosettaNet); however these do not match the popularity or prevalence of EDI. However there

    is no technical reason to exclude building out vertical/domain specific protocol handlers in

    line with the solution advocated here for EDI.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    5/79

    Page 5

    B2B Adoption blockers are in fact opportunities for MicrosoftMany surveys conducted have consistently indicated that key adoption blockers to

    implementing B2B/EDI solutions are related to investments; availability; and reliability of the

    computer applications. More than 2/3rd of typical survey respondents have cited initial

    investment of the computer system to be the prime adoption blocker. This is quite easy to

    comprehend given the complexity of setting up computer systems to conduct B2B

    transactions. These adoption blockers play easily into the strength of the Microsoft,

    especially around the hosted offering with Azure. Additionally BPD has the core abilities to

    design and implement on a topical solution B2B2.0!

    Results of a (typical and publicly available data) survey conducted in an emerging market

    are presented below.

    Factor Mean* Std Deviation

    Initial Investment 4.16 0.97

    Customer and supplier requirements 3.72 1.10

    Software reliability 3.68 1.10

    Software capability 3.66 1.08

    Software availability 3.66 0.88

    Hardware availability 3.59 0.74

    Hardware reliability 3.56 0.90

    Management Support 3.55 1.15

    Availability of EDI applications 3.54 1.14

    Internet skills/resources 3.54 0.85

    Availability of EDI standards 3.45 1.26Availability of maturity in EDI applications 3.25 1.08

    Strategic objectives 3.13 1.13End user acceptance 3.10 1.15

    Organizational resistance 2.82 1.12

    *measured using a 5-point scale

    State of the technologyEDI encoded documents are presented as delimited flat files and although the Standards

    (SDOs) and Industry Advisory organizations do not recommend transmission protocols, FTP

    (EDI over dedicated networks) and HTTP along with SMIME encryption and signature (EDI-

    INT or EDI over Internet) are the prevalent protocols with the latter gaining ground by theday.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    6/79

    Page 6

    While EDI documents over FTP are a prevalent protocol among the VAN (Value Added

    Networks) providers; EDI-INT is gaining market share over VAN solutions due to lowoperational costs and availability. Further dominant industry leaders (e.g., Walmart) force

    suppliers to use EDI-INT over VAN further eroding the latters market share. However VANs

    have some advantages over EDI-INT, mostly the requirement of only one physical

    connection, allowing multiple trading partners to be accessed via a single VAN connection

    reliably and securely. VAN revenues are expected to continue to decrease as EDI-INT

    increases. As this shift continues, VANs are focusing on the Value Added p art of their

    offerings, by offering more sophisticated mailbox features and reporting for the trading

    partners they service.

    There is a breed of ISV/Vendors that have sized on the opportunity to use the ubiquity of the

    internet for EDI-INT transmissions while providing the single point connectivity that VANsolutions offer. Such vendors are categorized as EDI Service Bureaus.

    The attractiveness of an EDI Service Bureaus is that they have out-of-box connectivity to

    100s of Partners. Partners are generally the mega corporations that everyone wants to

    transact with. The more comprehensive the list the grater attraction it is to its customer

    community. Customers are the smaller partners that are forced into EDI solutions by their

    larger partners.

    B2B 2.0 with Azure the durable competitive advantage for MicrosoftHaving established the business case for B2B and EDI messaging and armed with data that

    the TCO for computer systems are the adoption blocker; its fair to surmise that there is adurable business model for Microsoft to provide a B2B platform to Service Bureaus thereby

    providing a competitive opportunity vis--vis traditional VAN players in the B2B space.

    Now lets examine the possibility of delivering a solution to customer inline with the

    Microsoft Business Online Groups business model.

    Hosted Platform: Windows Azure with .NET Services and SQL Data Services providesthe ideal platform for developing and hosting a secure cloud scale B2B Server

    platform. The Server Platform would provide a range of essential (WCF) Services for

    EDI Parsing; Mapping framework; Batching; Enveloping; Ack Reconciliation; Partner

    Onboarding and Trading Partner Management Dashboard among other such

    essential services accessed via a browser based client. Identity Services would be

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    7/79

    Page 7

    deployed for security and SQL Data Services would act as the interim store and by

    choice the non repudiation-able receipt store.

    On-premise client application(s): Although document management (e.g.,upload/download of Excel documents) could be achieved via a browser client;

    additionally an on-premise black box solution is proposed. The client would

    comprise of a Silver Light client and use .NET components (WCF, WF, XSLT) and .EDI

    libraries to process, establish connectivity, authenticate and upload the documents

    to the Server. WCF streaming functionality with binary encoding and compression

    would provide the superior performance for uploading the XML based content; while

    Silver Light client would provide the rich client experience. Integration options

    (adapters?) would be available for a set of back end applications (e.g., Dynamics

    ERP). For customers desiring BPM and advanced connectivity options, the wellestablished BizTalk Server could be a preferred option with out-of-box connectivity toback end systems while being able to offer comprehensive EDI functionality.

    Importantly the client and dashboard will be customizable by the Service Bureau to

    address the domain needs.

    Monetization strategies will be in line with Business Online Service Groups licensing models

    usage or subscription based.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    8/79

    Page 8

    Unit Testing Schemas and Maps in BizTalk Server 2009 A Different

    Approach!

    By Sooraj Payyoormana, Senior Development Lead, Microsoft

    This article assumes you are familiar with BizTalk Server Schemas, Maps and Visual Studio 2008 Unit

    testing scripts.

    Audience: BizTalk Developers

    Technologies: BizTalk Server 2009, VS.NET 2008

    Skill level: Beginner to Expert

    The source code used in this article can be downloaded from the following location:

    http://cid-

    61b5fd0cc0cf5b2e.skydrive.live.com/self.aspx/Source%20Code/BTSUnitTests/BTSUnitTests.zip

    Summary

    There was an article on Unit Testing in BizTalk Server 2009 by Rajinder Singh in BizTalk Hotrod

    magazine1. I followed this article and the MSDN article on Using the Unit Testing Features with

    Schemas and Maps2

    to write unit test scripts for schema and map files.

    In this article, I am trying to explain the approaches I took to resolve the following issues which I faced

    during my unit test script development.

    Not able to do the unit testing on the schema which was referring other schemas that are part

    of different BizTalk assembly.

    Unit Test scripts are not working on the map file which uses multi-part message as input.

    Testing schema

    I needed to create automated unit test scripts for the SalesOrder and PurchaseOrder schemas.

    The following unit testing script was written to validate the SalesOrder schema using valid and invalid

    XML instances. Here I had written the unit test scripts based on the Unit Testing feature of BizTalk

    Server 2009.

    [TestMethod]publicvoid TestSOSchemaWithBuiltInMethod(){

    TestableSchemaBase salesOrderSchema = new SalesOrder.Schemas.SalesOrder();Assert.IsTrue(salesOrderSchema.ValidateInstance(VALID_SO_INSTANCE,

    Microsoft.BizTalk.TestTools.Schema.OutputInstanceType.XML), "Test failed for the ValidInstance scenario.");

    Assert.IsFalse(salesOrderSchema.ValidateInstance(INVALID_SO_INSTANCE,Microsoft.BizTalk.TestTools.Schema.OutputInstanceType.XML), "Test failed for the

    InValid Instance scenario.");

    1Issue 5 Q1 2009. See http://biztalkhotrod.com/Documents/BizTalk%20HotRod%20Magazine%20Q1%202009.pdf

    2http://msdn.microsoft.com/en-us/library/dd224279.aspx

    http://cid-61b5fd0cc0cf5b2e.skydrive.live.com/self.aspx/Source%20Code/BTSUnitTests/BTSUnitTests.ziphttp://cid-61b5fd0cc0cf5b2e.skydrive.live.com/self.aspx/Source%20Code/BTSUnitTests/BTSUnitTests.ziphttp://cid-61b5fd0cc0cf5b2e.skydrive.live.com/self.aspx/Source%20Code/BTSUnitTests/BTSUnitTests.ziphttp://cid-61b5fd0cc0cf5b2e.skydrive.live.com/self.aspx/Source%20Code/BTSUnitTests/BTSUnitTests.ziphttp://cid-61b5fd0cc0cf5b2e.skydrive.live.com/self.aspx/Source%20Code/BTSUnitTests/BTSUnitTests.zip
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    9/79

    Page 9

    }

    Let us see the Test Result after executing the above test method.

    The test passed without any errors.

    Now, let us write the unit test script for PurchaseOrder schema.

    The PurchaseOrder schema was created by importing two schemas named DocHeader schema and

    OrderComponents schema from different BizTalk assemblies.

    We will follow the above mentioned code to write the unit test script for PurchaseOrder schema.

    [TestMethod]publicvoid TestPOSchemaWithBuiltInMethod(){

    TestableSchemaBase purchaseOrderSchema = new

    PurchaseOrder.Schemas.PurchaseOrder();Assert.IsTrue(purchaseOrderSchema.ValidateInstance(VALID_PO_INSTANCE,Microsoft.BizTalk.TestTools.Schema.OutputInstanceType.XML), "Test failed for the validInstance scenario.");

    Assert.IsFalse(purchaseOrderSchema.ValidateInstance(INVALID_PO_INSTANCE,Microsoft.BizTalk.TestTools.Schema.OutputInstanceType.XML), "Test failed for theinvalid Instance scenario.");

    }

    Let us execute the test script and see the result.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    10/79

    Page 10

    The test failed! Are there any issues with the input instance XML files? Any issue with the schema(s)? Is

    the instance XML file path is valid?

    I manually verified whether the XML instance file path was wrong, whether the instances where

    valid/invalid for their scenario (against the schema) and whether there were issues with the schemas.

    There were no issues.

    Why is it Failing?

    The ValidateInstance method ofTestableSchemaBase class returns a Boolean value.

    Unfortunately, ValidateInstance method does not return any error information and it doesnt

    throw any exceptions. In the above code it returns false always, due to this, the first test method with

    Assert.IsTrueis failing. One of the reasons could be that the ValidateInstance method is not

    able to resolve the schemas specified in the import section which are referenced from other BizTalkassemblies. The Assert.IsFalse in the above code block will execute successfully as the

    ValidateInstance method returns false always.

    How can it be Resolved?

    The XmlReaderSettings and XmlReader3classes can be used to validate the schema. I wrote a

    helper class to do the XML validation using these classes. In the validation implementation code, the

    method takes the object of the schema class and the XML instance file path.

    publicstaticValidationResult ValidateSchema(TestableSchemaBase schemaObject, string

    xmlInstancePath)

    Now, create the XmlReaderSettings object using the schemaObject argument and set its

    ValidationType property and ValidationEventHandler event handler.

    XmlReaderSettings settings = new XmlReaderSettings();XmlSchemaSet schemaSet = new XmlSchemaSet();schemaSet.Add(schemaObject.Schema);settings.Schema = schemaSet;settings.ValidationType = ValidationType.Schema;settings.ValidationEventHandler += new

    ValidationEventHandler(SchemaReaderSettingsValidationEventHandler);

    Next, create the XmlReader object using the XmlReaderSettings object created above, and with

    the XML instance specified in the xmlInstancePath argument.

    using (XmlReader reader = XmlReader.Create(xmlInstancePath, settings)){

    XmlValidatingReader xmlValidator = new

    XmlValidatingReader(xmlInstanceReader);

    3TheXmlReaderclass can enforce validation using a document type definition (DTD) or XML Schema definition

    language (XSD) schema. Settings on the XmlReaderSettingsobject used by theCreatemethod determine what

    type of data validation, if any, theXmlReaderobject supports from MSDN.

    http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.create.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.create.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.create.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.create.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    11/79

    Page 11

    Read and validate the schema.

    while (reader.Read()){

    if (!_IsValid)break;

    }

    The code for the validation event handler:

    void SchemaReaderSettingsValidationEventHandler(object sender, ValidationEventArgsarguments)

    {if (arguments.Severity == XmlSeverityType.Error){

    _IsValid = false;validationMessage = arguments.Message;Trace.WriteLine(arguments.Message);

    }}

    The ValidationResult class code snippet:

    ////// Class for returning the validation results.///publicclassValidationResult{

    ////// Return true if the schema is valid else false.///publicbool IsValid { get; set; }////// Returns the error message if the schema validation is failed.///publicstring ValidationMessage { get; set; }

    }

    Thats it. You are now ready to call the ValidateSchema method from the unit test script:

    Finally this is the customized unit test script for testing PurchaseOrder schema:

    [TestMethod]publicvoid TestPOSchemaWithCustomMethod(){

    TestableSchemaBase purchaseOrderSchema = newPurchaseOrder.Schemas.PurchaseOrder();

    ValidationResult result1 =XmlValidationHelper.ValidateSchema(purchaseOrderSchema, VALID_PO_INSTANCE);

    Assert.IsTrue(result1.IsValid, "Test failed for the Valid Instancescenario. Exception: {0}", result1.ValidationMessage);

    ValidationResult result2 =

    XmlValidationHelper.ValidateSchema(purchaseOrderSchema, INVALID_PO_INSTANCE);Assert.IsFalse(result2.IsValid, "Test failed for the InValid Instance

    scenario. Exception: {0}", result.ValidationMessage);}

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    12/79

    Page 12

    In the above code block, we are creating the object of the PurchaseOrder schema and passes as the

    first argument to the ValidateSchemamethod of the XmlValidationHelper class. The

    ValidationResult class is used to capture the error message while validating the schema. The

    IsValid property returns the Boolean value, which indicates the validation is successful or not and the

    ValidationMessage returns the error message.

    Now we will execute this test script and see the test result.

    Yes, this time the test passed without any errors.

    Now lets look at Map Files

    The PurchaseOrder schema instance should be transformed as a SalesOrder schema instance. The

    map file which is created for the transformation takes a multi-part message as the input and creates the

    instance of the SalesOrder schema instance as output. One part of the multi-part message input is the

    instance of the PurchaseOrder schema and the other is the instance of the Store schema, which is

    created using a .NET assembly from the Orchestration. I have created an instance file for this multi-part

    message type using the Test Map menu option of Visual Studio context menu.

    The following unit test script is written for testing the map file, using the TestMap method of

    TestableMapBase class.

    [TestMethod]publicvoid TestSOMapping(){

    TestableMapBase target = newTransformSOMessage();InputInstanceType inputType = InputInstanceType.Xml;OutputInstanceType outputType = OutputInstanceType.XML;target.TestMap(INPUT_FILE, inputType, OUTPUT_FILE, outputType);Assert.IsTrue(File.Exists(OUTPUT_FILE), "Failed to generate output

    file..");ValidationResult vr = XmlValidationHelper.ValidateOutput(OUTPUT_FILE,

    EXPECTED_FILE);Assert.IsTrue(vr.IsValid, "Mapping test failed. Exception {0}",

    vr.ValidationMessage);

    }

    We will execute the above test script and see the result.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    13/79

    Page 13

    The test is failed!

    Why is it Failing?

    The generated output file and the expected results are not matching. The TestMapmethod generates

    output with whitespace. Another reason could be that the unit test feature of BizTalk Server 2009

    doesnt support multi-part message types for testing map files.

    How can it be Resolved?

    By using the XslCompiledTransform 4class we can transform the schema instance with the help of

    XSLT specified in the map file. BizTalk Server does the transformation based on the XSLT 1.0 syntax.

    I wrote a c# function using the XslCompiledTransform class. Here is the code:

    publicstaticValidationResult TestMapper(string inputPath, TransformBase mapperClass,string outPutPath,

    string expectedResultPath){

    string xsltContent = mapperClass.XmlContent;ValidationResult vr = newValidationResult { IsValid = true,

    ValidationMessage = string.Empty };using (XmlTextReader xmlReader = newXmlTextReader(new

    StringReader(xsltContent))){

    XPathDocument inputDocument = newXPathDocument(inputPath);XslCompiledTransform myXslTrans = newXslCompiledTransform();myXslTrans.Load(xmlReader);XmlWriterSettings settings = newXmlWriterSettings();settings.OmitXmlDeclaration = true;using (XmlWriter xmlWriter = XmlWriter.Create(outPutPath, settings)){

    myXslTrans.Transform(inputDocument, mapperClass.TransformArgs,xmlWriter);

    }

    }if (File.Exists(outPutPath)){

    4The XslCompiledTransform class is an XSLT processor that supports the XSLT 1.0 syntax. It is a new

    implementation and includes performance gains when compared to the obsoleteXslTransformclass. The structureof the XslCompiledTransform class is very similar to theXslTransformclass. TheLoadmethod loads and

    compiles the style sheet, while theTransformmethod executes the XSLT transform. From MSDN.

    http://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.load.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.transform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.load.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.load.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.load.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.transform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.transform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.transform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.transform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.load.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspxhttp://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltransform.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    14/79

    Page 14

    vr = XmlValidationHelper.ValidateOutput(outPutPath,

    expectedResultPath);}else{

    vr.IsValid = false;vr.ValidationMessage = "Mapping failed..Output file is not generated";

    }return vr;

    }

    string xsltContent = mapperClass.XmlContent;

    The above code returns the XSLT defined in the map class. Using that XSLT, we will be able to generate a

    XML file which is the expected output from the map.

    settings.OmitXmlDeclaration = true;

    The OmitXmlDeclarationproperty is used to create the XML without having the XML declaration andallow us to do the comparison between the generated output file with the expected result.

    XmlValidationHelper.ValidateOutput methodis used here to compare both the XML file and it

    reports the errors during the comparison. This code is available in the above mentioned for download.

    Finally the unit test script will look like this:[TestMethod]

    publicvoid TestSOMappingUsingCustomMethod(){

    TransformSOMessage salesOrderMap = newTransformSOMessage();ValidationResult vr = XmlMapperHelper.TestMapper(INPUT_FILE,

    salesOrderMap, OUTPUT_FILE, EXPECTED_FILE);Assert.IsTrue(vr.IsValid, "Mapping test failed. Exception {0}",

    vr.ValidationMessage);}

    Let us execute the test script and see the result.

    Wow! The test passed without any errors.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    15/79

    Page 15

    Conclusion

    The ValidateInstance method of the TestableSchemaBase class does not return any error

    information, it always returns either true or false. Due to this we are not able to find the exact error with

    the schema unit tests. My article is trying to address this issue and helps to find the exact error while

    validating the schema.

    Even though you will be able to find out the errors while testing the map files using the TestMap

    method of the TestableMapBase class, we are not be able to compare the output file with the

    expected result. Also, the Unit Testing feature of BizTalk Server 2009 doesnt support unit testing of map

    file which uses the multi-part type messages.

    My article is trying to address these issues of map file unit testing and reports the issues.

    Advantages with the above approaches

    Generic and reusable code to do the unit test scripts on map and schema files Better validation and error reporting

    Write unit test scripts to test and validate map, when the input for the map file is a multi-part

    message

    Write unit test scripts to test schema, when there are one or more external referenced schemas

    imported in the schema

    Disadvantages with the above approaches

    Developer should write the custom classes and methods for validating the Schemas and map

    files for the first time. Later this can be reused in other unit test projects.

    The developer should know more on XML, XSD and its related classes and methods in .NET.

    Whereas with the BizTalk unit test script methods, the developer need not know these

    classes/methods.

    Happy Unit Testing!

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    16/79

    Page 16

    Book Review for "SOA Patterns with BizTalk Server 2009" By Richard

    Seroter

    I was recently asked to review this book. Like the title implies this book is shows you how to use BizTalk

    to implement Service Oriented Architecture. It is written for developers and architects. It is not meant to

    be a BizTalk tutorial. SOA cannot be implemented by any one tool. However anyone trying to implement

    Service Oriented applications on Microsoft Platform should learn more about Windows Communication

    Foundation and BizTalk Server.

    Chapter 1 gives a brief overview of BizTalk Architecture and also describes artifacts needed to develop

    BizTalk based solutions.

    Chapter 2 gives you primer of Windows Communication Foundation. You will need to rely on other

    sources to learn more about WCF.

    Chapter 3 describes BizTalk WCF Adapters. It also shows how to use WCF adapters from Orchestrations

    and Messaging only scenarios. It shows how to publish Orchestrations as WCF service and how to

    consume a WCF Service from an Orchestration. This chapter did a great job in explaining how to use

    BizTalk WCF adapters.

    Chapter 4 starts by explaining core principles of SOA. It expands on this principles and shows how

    BizTalk can be used to design SOA solutions. It also identifies various message exchange patterns and

    service types.

    Chapter 5 does an excellent job in documenting the best practices for building schemas that will work

    well with the type of service you have chosen. It talks about building canonical schemas and benefits,limitations of schema reuse. It also shows the impact of data type and node definition on the client

    code. There is also a section on using generic schemas and tips for building contract first endpoints. This

    chapter is must read for anyone who is designing schemas in a SOA based solution.

    Chapter 6 explains benefits of asynchronous communication and how one can implement them with

    WCF. It also shows how to implement such a solution with BizTalk. There is also a section on queue

    based communication.

    Chapter 7 you will learn about Orchestrations. It explains Direct binding and dynamic service ports. It

    also shows how to implement various message exchange patterns in an Orchestration. There is a

    section that shows how to chain Orchestrations together with the help of Business Rules Engine. The

    chapters finishes with a section on role of Transactions and Complex Event Processing

    Chapter 8 is must read for anyone who is grappling with versioning schemas, services and

    Orchestrations. Versioning schemas and other BizTalk artifacts has always been tricky. This chapter is

    one of the best reference you will find out this topic.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    17/79

    Page 17

    Chapter 9 describes WCF SQL Server Adapter that was recently released as a part of BizTalk Adapter

    Pack 2.0. It shows the differences between the old SQL adapter and the new adapter. It also shows you

    various ways in which you can use this new adapter.

    Chapter 10 UDDI V3 is now a part of BizTalk 2009. This chapter explains UDDI and shows you how to use

    the UDDI Service that is a part of BizTalk 2009. There is not much documentation out there for UDDI and

    this chapter will be a great resource for anyone interested in using UDDI.

    Chapter 11 Gives you an overview of ESB Guidance 2.0. It describes various components of the ESB

    Toolkit. It also shows how to implement various scenarios with ESB Toolkit. This chapter did a great job

    in covering ESB Toolkit.

    Chapter 12 This chapter briefly talks about Dublin, .Net Services and Oslo.

    I found this book to be very easy to read. Richard has a knack for explaining concepts clearly with the

    help of examples. There are not many books available that do such a good job of showing how to use

    BizTalk to implement SOA. Anyone implementing SOA solutions on Microsoft platform will benefit from

    this book.

    Rajinder Singh

    Technical Solutions Professional

    Microsoft

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    18/79

    Page 18

    How to Throw Typed Fault Exceptions from Orchestrations Published as

    WCF Services

    By Paolo Salvatori, Principal Program Manager, Customer Experience Team, Microsoft Italy

    In general, a WCF Web Service can return two types of SOAP faults: typed and untyped SOAPfaults. BizTalk development tools allow you to publish an Orchestration was a WCF Service. Outof the box BizTalk Orchestrations published as WCF Services can throw untyped faults. Thisarticle will show you how to throw Typed Faults from Orchestrations published as a WCFService.

    Typed Faults

    In order to throw a typed fault, a service operation must be decorated with aSystem.ServiceModel.FaultContractAttributethat specifies a fault data contract defined earlier.The following code snippet shows a WCF web service called HelloWorld which implements theIHelloWorld service or contract interface. This interface exposes a single synchronous operationcalled SayHello that is decorated with the FaultContractAttribute. The attribute declares that theSayHello method can throw a typed fault exception defined by the CustomError data contractclass. The implementation of the SayHello method in the HelloWorld class checks if theincoming request is null and in this case it throws an error of typeFaultException.

    namespace Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.Services{

    [Serializable][DataContract(Name = "HelloWorldRequest", Namespace =

    "http://microsoft.biztalk.cat/10/helloworld")]publicclassHelloWorldRequest{

    ...}

    [Serializable][DataContract(Name = "HelloWorldResponse", Namespace =

    "http://microsoft.biztalk.cat/10/helloworld")]publicclassHelloWorldResponse{

    ...}

    [Serializable][DataContract(Name = "CustomError", Namespace =

    "http://microsoft.biztalk.cat/10/customerror")]publicclassCustomError

    { ...}

    [ServiceContract(Name = "HelloWorld", Namespace =

    http://msdn.microsoft.com/en-us/library/system.servicemodel.faultcontractattribute.aspxhttp://msdn.microsoft.com/en-us/library/system.servicemodel.faultcontractattribute.aspxhttp://msdn.microsoft.com/en-us/library/system.servicemodel.faultcontractattribute.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    19/79

    Page 19

    "http://microsoft.biztalk.cat/10/helloworld")]

    publicinterfaceIHelloWorld{

    [OperationContract(Action = "SayHello", ReplyAction = "SayHello",ProtectionLevel = ProtectionLevel.None)]

    [FaultContract(typeof(CustomError), Action = "CustomErrorFault")]HelloWorldResponse SayHello(HelloWorldRequest request);

    }

    [ServiceBehavior(Name = "HelloWorld", Namespace ="http://microsoft.biztalk.cat/10/helloworld")]

    publicclassHelloWorld : IHelloWorld{

    [OperationBehavior]publicHelloWorldResponse SayHello(HelloWorldRequest request){

    if (request == null || string.IsNullOrEmpty(request.Name)){

    throw CreateFault(NameCannotBeNullOrEmpty);}returnnewHelloWorldResponse(string.Format(SayHelloFormat,

    request.Name));}

    private FaultException CreateFault(string message){

    ...return fault;

    }}

    }

    Untyped Faults

    Untyped SOAP faults are those that do not require a service operation to be decorated with a

    FaultContractAttribute that specify a custom data contract class.

    BizTalk Orchestrations and Typed Faults

    BizTalk Server 2006 R2 and BizTalk Server 2009 allow handling typed fault contracts whenconsuming WCF services from within orchestrations. The steps necessary to implement thistechnique are clearly described in the article How to Handle Typed Fault Contracts inOrchestrations on MSDN. Instead, WCF adapters actually do not support processing typedfault contract exceptions within orchestrations published as WCF services. However, untypedSOAP faults can always be returned by orchestrations or pipelines. For more information on thistopic review the article How to Throw Fault Exceptions from Orchestrations Published as WCFServices on MSDN.

    This constraint arises from how the Receive Handler of WCF Adapters is actually implemented.The WCF Receive Adapter instantiates a singleton instance of the BizTalkServiceInstance classfor each WCF Receive Location. This class can be found in theMicrosoft.BizTalk.Adapter.Wcf.Runtime.dll assembly. In particular, as you can see in the picturebelow, the BizTalkServiceInstance class is decorated with the attribute

    http://msdn.microsoft.com/en-us/library/bb246117.aspxhttp://msdn.microsoft.com/en-us/library/bb246117.aspxhttp://msdn.microsoft.com/en-us/library/bb246117.aspxhttp://msdn.microsoft.com/en-us/library/bb246117.aspxhttp://msdn.microsoft.com/en-us/library/bb226394.aspxhttp://msdn.microsoft.com/en-us/library/bb226394.aspxhttp://msdn.microsoft.com/en-us/library/bb226394.aspxhttp://msdn.microsoft.com/en-us/library/bb226394.aspxhttp://msdn.microsoft.com/en-us/library/bb226394.aspxhttp://msdn.microsoft.com/en-us/library/bb226394.aspxhttp://msdn.microsoft.com/en-us/library/bb246117.aspxhttp://msdn.microsoft.com/en-us/library/bb246117.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    20/79

    Page 20

    ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,

    ConcurrencyMode=ConcurrencyMode.Multiple).

    Therefore, all the incoming requests towards a given WCF Receive Location are managed bythe same singleton object. When you enable a WCF Receive Location, the Adapter initializesand opens a dedicated instance of a ServiceHost-derived class (WebServiceHost), whichdynamically builds the WCF runtime components within the in-process or isolated host process.This includes the channel stack, dispatcher, and generic service instance. Almost all of the WCFadapters can be hosted within the BizTalk service process itself the only exception is WCF-CustomIsolated, which must be used in a BizTalk isolated host by design. Even the HTTPadapters can be hosted in-process now. The WCF Adapters build the generic service contractsshown in the table below. Each service contract implemented by the BizTalkServiceInstancecovers a different scenario.

    [ServiceContract(Namespace = "http://www.microsoft.com/biztalk/2006/r2/wcf-adapter")]publicinterfaceIOneWayAsync{

    // Methods[OperationContract(AsyncPattern = true, IsOneWay = true, Action = "*")]IAsyncResult BeginOneWayMethod(Message message, AsyncCallback callback, object state);[OperationContract(IsOneWay = true, Action = "BizTalkSubmit")]

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Reflector1_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Reflector1_2.jpg
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    21/79

    Page 21

    void BizTalkSubmit(Message message);

    void EndOneWayMethod(IAsyncResult result);}

    [ServiceContract(Namespace = "http://www.microsoft.com/biztalk/2006/r2/wcf-adapter")]publicinterfaceIOneWayAsyncTxn{

    // Methods[OperationContract(AsyncPattern = true, IsOneWay = true, Action = "*")]IAsyncResult BeginOneWayMethod(Message message, AsyncCallback callback, object state);[OperationContract(IsOneWay = true, Action = "BizTalkSubmit")]void BizTalkSubmit(Message message);void EndOneWayMethod(IAsyncResult result);

    }

    [ServiceContract(Namespace = "http://www.microsoft.com/biztalk/2006/r2/wcf-adapter")]publicinterfaceITwoWayAsync{

    // Methods[OperationContract(AsyncPattern = true, IsOneWay = false, Action = "*", ReplyAction =

    "*")]IAsyncResult BeginTwoWayMethod(Message message, AsyncCallback callback, object state);[OperationContract(IsOneWay = false, Action = "BizTalkSubmit")]Message BizTalkSubmit(Message message);Message EndTwoWayMethod(IAsyncResult result);

    }

    [ServiceContract(Namespace = "http://www.microsoft.com/biztalk/2006/r2/wcf-adapter")]publicinterfaceITwoWayAsyncVoid{

    // Methods[OperationContract(AsyncPattern = true, IsOneWay = false, Action = "*", ReplyAction =

    "*")]IAsyncResult BeginTwoWayMethod(Message message, AsyncCallback callback, object state);[OperationContract(IsOneWay = false, Action = "BizTalkSubmit")]void BizTalkSubmit(Message message);void EndTwoWayMethod(IAsyncResult result);

    }

    [ServiceContract(Namespace = "http://www.microsoft.com/biztalk/2006/r2/wcf-adapter")]publicinterfaceITwoWayAsyncVoidTxn{

    // Methods[TransactionFlow(TransactionFlowOption.Mandatory), OperationContract(AsyncPattern =

    true, IsOneWay = false, Action = "*", ReplyAction = "*")]IAsyncResult BeginTwoWayMethod(Message message, AsyncCallback callback, object state);[TransactionFlow(TransactionFlowOption.Mandatory), OperationContract(IsOneWay = false,

    Action = "BizTalkSubmit")]void BizTalkSubmit(Message message);void EndTwoWayMethod(IAsyncResult result);

    }

    As you can easily see in the code above, all the service contracts implemented by theBizTalkServiceInstance Class are generic and asynchronous. In fact, one-way service

    operations are decorated with [OperationContract(AsyncPattern = true, IsOneWay = true, Action= "*")] attribute, while request-response methods are decorated with the[OperationContract(AsyncPattern = true, IsOneWay = false, Action = "*", ReplyAction = "*")]attribute. Besides, they receive a generic inbound message of typeSystem.ServiceModel.Channels.Messageand eventually return a message of the same type.

    http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspxhttp://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspxhttp://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    22/79

    Page 22

    As a consequence, these methods can accept any request message and eventually process

    any reply message. However, since these operations are generic and untyped, they are notdecorated by any FaultContractAttribute. As a consequence, WCF Receive Locations cannotreturn typed fault exceptions. Since every WCF Receive Location is implemented as aninstance of the BizTalkServiceInstance and this class cannot be customized or inherited toexpose typed service contracts, BizTalk Server does not natively support throwing typed faultexceptions within orchestrations published as WCF services or more in general throwing typedfault exceptions within a WCF Receive Location.

    At this point a question arises: is there any workaround to throw typed fault exceptions withinorchestrations published as WCF services? The answer, fortunately, is yes.

    The Solution

    The WCF-Custom and WCF-CustomIsolated Adapters provided by BizTalk Server 2006 R2 and

    BizTalk Server 2009 allow to define a custom WCF binding configuration to meet your precisecommunication needs. These adapters can be used to define custom WCF configurations forSend Ports or Receive Locations and extend their standard functionality using customcomponents as endpoint and service behaviors, message inspectors, custom bindings, bindingelements, channels, etc. Therefore, I decided to create the following custom components:

    Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.WsdlExportExtensions assembly:flattens and extends the WSDL generated by the BizTalk WCF Service PublishingWizard to enable WCF Receive locations to expose typed soap faults.

    Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.MessageInspector assembly:intercepts a reply message and when this latter is a fault, it creates and returns a typedfault message.

    The following picture depicts the architecture of the proof of concept I implemented to test thesecomponents:

    1. A WCF-CustomIsolated Request-Response Receive Location receives a new xmldocument from a client application.

    2. The XML disassembler component within the XMLTransmit pipeline promotes theMsgType context property. The Message Agent submits the incoming message to theMessageBox (BizTalkMsgBoxDb).

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Architecture_6.jpg
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    23/79

    Page 23

    3. The inbound request starts a new instance of the HelloWorld orchestration type.

    4. The orchestration checks the incoming HelloWorldRequest message, and if the Nameelement is null or empty, it creates and return a new fault message of type CustomError.Otherwise, the orchestration returns a reply message of type HelloWorldResponse.

    5. The HelloWorld orchestration publishes the reply message to the MessageBox(BizTalkMsgBoxDb).

    6. The response message is retrieved by the WCF-CustomIsolated Request-ResponseReceive Location.

    7. The reply message is processed by the CustomErrorMessageInspector component. Ifthe response is a fault message, it creates a new typed fault message using theconfiguration data set on the Receive Location.

    8. The reply message is returned to the client application.

    The following picture shows the XML Schema which defines the CustomError typed fault.

    The following figure shows the configuration of the WCF-CustomIsolated Request-ResponseReceive Location.

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/CustomErrorXsd_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/CustomErrorXsd_6.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/CustomErrorXsd_6.jpg
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    24/79

    Page 24

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/BindingTab_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/GeneralTab_2.jpg
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    25/79

    Page 25

    The Receive Location exposes an endpoint that uses the WsHttpBinding and make use of theserviceThrottling service behavior (seeSystem.ServiceModel.Description.ServiceThrottlingBehaviorfor more information) and 2 customendpoint behaviors:

    customError wsdlExport

    These components must be configured in the machine.config as follows:

    ...

    ...

    ...

    http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspxhttp://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspxhttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/MessagesTab_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/CustomErrorTab_2.jpghttp://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    26/79

    Page 26

    The Include exception detail in faults option must be set on the Messages tab to enable theWCF Receive Location to return the error detail in fault messages. Below you can see the codeof the CustomErrorMessageInspector component. The constructor retrieves configuration datafrom the Receive Port configuration, while the IDispatchMessageInspector::BeforeSendReplymethod intercepts the reply message and if this latter is a fault, it generates a typed fault

    exception using the configuration data.

    namespace Microsoft.BizTalk.CAT.Samples.PublishTypedFaults.MessageInspector{

    ////// This class can be customized to create a message inspector.///publicclassCustomErrorMessageInspector : IDispatchMessageInspector,

    IClientMessageInspector{

    #region Private Constants...#endregion

    #region Private Fields...#endregion

    #region Public Constructorspublic CustomErrorMessageInspector(bool enabled,

    bool traceEnabled,int maxBufferSize,string typedFaults)

    {this.enabled = enabled;this.traceEnabled = traceEnabled;this.maxBufferSize = maxBufferSize;this.typedFaults = typedFaults;

    try{

    if (!string.IsNullOrEmpty(typedFaults)){

    TypedFaults faultData = SerializationHelper.XmlDeserialize(typedFaults,typeof(TypedFaults)) as TypedFaults;

    if (faultData != null &&faultData.FaultList != null &&

    faultData.FaultList.Count > 0){

    for (int i = 0; i < faultData.FaultList.Count; i++){

    if (!string.IsNullOrEmpty(faultData.FaultList[i].Action) &&

    http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.aspxhttp://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.idispatchmessageinspector.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    27/79

    Page 27

    !string.IsNullOrEmpty(faultData.FaultList[i].Name))

    {faults.Add(string.Format(MessageTypeFormat,

    faultData.FaultList[i].Namespace,faultData.FaultList[i].Name ??

    string.Empty),new

    CustomErrorFaultInfo(faultData.FaultList[i].Action,

    faultData.FaultList[i].Reason));}

    }}

    }}catch (Exception ex){

    EventLog.WriteEntry(Source, ex.Message, EventLogEntryType.Error);}

    }#endregion

    #region IDispatchMessageInspector Memberspublicobject AfterReceiveRequest(ref Message request, IClientChannel channel,

    InstanceContext instanceContext){

    return request.Headers.Action;}

    publicvoid BeforeSendReply(ref Message reply, object correlationState){

    try{

    if (enabled &&reply.IsFault &&string.Compare(((string)correlationState), TransferGetNamespace, true) !=

    0){

    string action = correlationState asstring;MessageFault fault = MessageFault.CreateFault(reply, maxBufferSize);string detail = fault.Reason.ToString();CustomErrorMessageFault faultMessage = new CustomErrorMessageFault(faults,

    newFaultCode(FaultCodeName), detail, traceEnabled);

    Message message = Message.CreateMessage(reply.Version, faultMessage, null);message.Headers.CopyHeadersFrom(reply.Headers);message.Properties.CopyProperties(reply.Properties);if (string.IsNullOrEmpty(faultMessage.Action)){

    message.Headers.Action = action;}else{

    message.Headers.Action = faultMessage.Action;}reply = message;

    }

    }catch (Exception ex){

    EventLog.WriteEntry(Source, ex.Message, EventLogEntryType.Error);throw ex;

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    28/79

    Page 28

    }

    return;}#endregion

    #region IClientMessageInspector Memberspublicvoid AfterReceiveReply(ref Message reply, object correlationState){

    return;}

    publicobject BeforeSendRequest(ref Message request, IClientChannel channel){

    returnnull;}#endregion

    }}

    The following table contains the XML snippet used as configuration data for theCustomErrorMessageInspector component. As you can see, it allows defining multiple typedfaults in a declarative way. At runtime it will use this data to recognize a fault reply message andaccordingly set the Action and Reason properties of the fault message returned.

    SayHelloCustomErrorhttp://microsoft.biztalk.cat/10/customerrorCustom Error

    If you set the TraceEnabled property to true, at runtime the CustomErrorMessageInspector

    component will produce a trace that you can intercept and review with a tool such asDebugasshown in the picture below.

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://technet.microsoft.com/en-us/sysinternals/bb896647.aspxhttp://technet.microsoft.com/en-us/sysinternals/bb896647.aspxhttp://technet.microsoft.com/en-us/sysinternals/bb896647.aspxhttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewCustomError_2.jpghttp://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    29/79

    Page 29

    The WCF-Receive Location can be created using theBizTalk WCF Service Publishing Wizard.

    In particular, this allows to create a WCF Receive Location to expose the HelloWorldorchestration as a WCF service. Moreover, setting the Enable metadata endpoint option itspossible to enable the WCF Receive Location to expose a Metadata Endpoint.

    This allows a developer to use Visual Studio or a tool such assvcutilto generate a proxy class

    to invoke the WCF Receive Location. Now, lets say that you want to create a WCF clientapplication to invoke the WCF Receive Location. Within Visual Studio you can create a newWindows Application, right-click the project inside the Solution Explorer and then select AddService Reference. If the WCF Receive Location exposes a Metadata Endpoint, this operationwill create a proxy class to invoke the corresponding WCF web service. However, if you reviewthe code and in particular the contract interface, youll realize that the SayHello method is notdecorated with a FaultContractAttribute. This is due to the fact, that since BizTalk Server doesnot support throwing typed fault exceptions, the native wsdl returned by the Metadata Endpointexposed by the WCF Receive location does not contain any soap fault message. In order to sortout this problem, you can adopt one of the following techniques:

    Create and expose a custom wsdl that contains the definition of your typed soap faults. Create a custom endpoint behavior to dynamically modify the wsdl produced by BizTalk.

    The first technique is quite straightforward:

    You manually define a custom wsdl using a text or xml editor. You publish the resulting wsdl file to IIS (e.g.http://localhost/samples/service.wsdl) You configure your WCF-Custom or WCF-CustomIsolated Receive Location to expose

    metadata and in particular the newly created wsdl file.

    http://msdn.microsoft.com/en-us/library/bb226547.aspxhttp://msdn.microsoft.com/en-us/library/bb226547.aspxhttp://msdn.microsoft.com/en-us/library/bb226547.aspxhttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/BizTalkWCFServicePublishingWizard_2.jpghttp://msdn.microsoft.com/en-us/library/aa347733.aspxhttp://msdn.microsoft.com/en-us/library/aa347733.aspxhttp://msdn.microsoft.com/en-us/library/aa347733.aspxhttp://localhost/samples/service.wsdlhttp://localhost/samples/service.wsdlhttp://localhost/samples/service.wsdlhttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/BizTalkWCFServicePublishingWizard_2.jpghttp://localhost/samples/service.wsdlhttp://msdn.microsoft.com/en-us/library/aa347733.aspxhttp://msdn.microsoft.com/en-us/library/bb226547.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    30/79

    Page 30

    In order to accomplish the finale step, you can proceed as follows:

    Start the BizTalk Server Administration Console. Open your WCF-Custom/WCF-CustomIsolated Receive Location. Click the Configure button in the Transport section. Click the Behavior tab. Right-click the Service Behavior node and choose to Add Extension. In the Select Behavior Extension window, choose the serviceMetadata component. Set the value of the httpGetEnabled property of the serviceMetadata behavior to True

    (see the picture below). Set the value of the externalMetadataLocation property of the serviceMetadata behavior

    to the url of your hand-built wsdl (see the picture below).

    The second technique consists in creating a custom component called WsdlExtensions tomodify at run-time the wsdl returned by the Metadata Endpoint exposed by a WCF-

    http://c/Users/paolos/AppData/Local/Temp/WindowsLiveWriter1286139640/supfilesD058C3C/serviceMetadata[4].jpghttp://c/Users/paolos/AppData/Local/Temp/WindowsLiveWriter1286139640/supfilesD058C3C/serviceMetadata[4].jpghttp://c/Users/paolos/AppData/Local/Temp/WindowsLiveWriter1286139640/supfilesD058C3C/serviceMetadata[4].jpghttp://c/Users/paolos/AppData/Local/Temp/WindowsLiveWriter1286139640/supfilesD058C3C/serviceMetadata[4].jpghttp://c/Users/paolos/AppData/Local/Temp/WindowsLiveWriter1286139640/supfilesD058C3C/serviceMetadata[4].jpghttp://c/Users/paolos/AppData/Local/Temp/WindowsLiveWriter1286139640/supfilesD058C3C/serviceMetadata[4].jpg
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    31/79

    Page 31

    Custom/WCF-CustomIsolated Receive location. This component is implemented as an a

    custom endpoint behavior and it can be used along with any WCF-Custom or WCF-CustomIsolated Receive Location, as shown in the picture below.

    The WsdlExtensions property exposed by the component accepts an XML snippet that allows tospecify how the wsdl has to be customized at runtime.

    bts

    CustomErrorhttp://microsoft.biztalk.cat/10/customerror

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/WsdlExportTab_4.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/WsdlExportTab_4.jpg
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    32/79

    Page 32

    HelloWorld_SayHello_CustomErrorFault_FaultMessagehttp://microsoft.biztalk.cat/10/customerror

    detailCustomError

    HelloWorld

    SayHello

    CustomErrorFault

    HelloWorld_SayHello_CustomErrorFault_FaultMessage

    As shown in the picture above, the components allows to define the following information:

    The prefix for the namespace of new messages created inside the wsdl. One or multiple Xml Schemas each defining a different typed fault. These schemas must

    be deployed to BizTalk. At runtime, the component is able to retrieve the content of eachschema from the BizTalkMgmtDb that subsequently is inserted in the outbound wsdl.

    One or multiple fault messages, each containing one or multiple parts. One or multiple operation-fault associations. At runtime the component search through

    the original wsdl structure and creates faults accordingly.

    At runtime the WsdlExtensions component validates the XML configuration specified on the portand if the TraceEnabled property is set to true, it produces a trace with a tool such asDebugasshown in the picture below.

    Formatted: Font: (Default) Times New

    Roman, 12 pt, Font color: Blue

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://technet.microsoft.com/en-us/sysinternals/bb896647.aspxhttp://technet.microsoft.com/en-us/sysinternals/bb896647.aspxhttp://technet.microsoft.com/en-us/sysinternals/bb896647.aspxhttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DebugViewAddServiceReference_2.jpghttp://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    33/79

    Page 33

    The following picture shows the wsdl produced by the WsdlExtensions component at runtime. In

    particular, the parts added by the component are highlighted by a red frame.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    34/79

    Page 34

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Wsdl_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Wsdl_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/Wsdl_2.jpg
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    35/79

    Page 35

    Note: Flattening the wsdl to include the XML schemas used to define messages allows to make

    the wsdl document compatible with non-Microsoft development environments. In fact, VisualStudio supports import and include directives in a wsdl, but some non-Microsoft developmentenvironments are not able to consume the wsdl exposed by a WCF web service.

    Note: the XML Schemas defining the structure of the XML configuration data consumed atruntime respectively by the CustomErrorMessageInspector and by theWsdlExportEndpointBehavior can be found inside the BehaviorSchemas project. Thecorresponding assembly doesnt need to be deployed to BizTalk Server.

    Proof of Concept in Action

    In order to test the WCF custom components, I created a WinForms application. In particular,when I leave the Name textbox blank and press the Call button, the HelloWorld orchestrationreturns a fault message. The client application intercepts the error with a catch

    (FaultException ex) block and opens a MessageBox to showthe detail of the exception.

    Show me the code!

    At this point, you are probably saying ok, cool, wheres the code?

    Well, I packaged the code in 2 different flavors:

    -BizTalk Server 2009

    -BizTalk Server 2006 R2

    http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DriverApplication_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DriverApplication_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DriverApplication_2.jpghttp://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DriverApplication_2.jpghttp://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2009.zip?ccr=7573http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2009.zip?ccr=7573http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2009.zip?ccr=7573http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2006R2.zip?ccr=657http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2006R2.zip?ccr=657http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2006R2.zip?ccr=657http://blogs.msdn.com/blogfiles/paolos/WindowsLiveWriter/HowtoThrowTypedFaultExceptionsfromOrches_A9A8/DriverApplication_2.jpghttp://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2006R2.zip?ccr=657http://cid-09dba4a06b360a65.skydrive.live.com/self.aspx/Pubblica/PublishTypedFaultsBTS2009.zip?ccr=7573
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    36/79

    Page 36

    Obviously, everything there are many ways to implement the same functionalities, so Id be glad

    if you could leave a message on my blog(http://blogs.msdn.com/paolos/) and let me know howyou used/customized/improved my code. Enjoy! ;-)

    http://blogs.msdn.com/paolos/http://blogs.msdn.com/paolos/http://blogs.msdn.com/paolos/http://blogs.msdn.com/paolos/
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    37/79

    Page 37

    BizTalk Resources

    We will use this section to document other BizTalk resources.

    BizTalk 24x7

    This site has a lot of great information about Books, Technical articles, Vides, blogs, Tools related to

    BizTalk.

    http://www.biztalk247.com/

    BizTalk Gurus

    This is another BizTalk community site. You can sign up for their newsletter too.

    http://www.biztalkgurus.com/

    BizTalk Server Customer Advisory Team

    This team consists folks with deep knowledge about BizTalk. They have produced excellent

    documentation about BizTalk operations, performance optimization etc.

    http://msdn.microsoft.com/en-us/biztalk/dd876758.aspx

    Recently Released Documentation

    BizTalk Server 2009 Install Documentation - June 2009 Update

    http://msdn.microsoft.com/en-us/biztalk/dd876758.aspx

    BizTalk Server 2009 Operations Guide - July 2009

    This document is a collaboration of Technical folks with real-world experience. Anyone working

    with BizTalk will find invaluable information in this guide.

    Download it here

    http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=46a77327-affb-

    4ca2-9451-67912babbb03

    Read it online

    http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=46a77327-affb-4ca2-9451-67912babbb03http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=46a77327-affb-4ca2-9451-67912babbb03http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=46a77327-affb-4ca2-9451-67912babbb03http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=46a77327-affb-4ca2-9451-67912babbb03http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=46a77327-affb-4ca2-9451-67912babbb03
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    38/79

    Page 38

    http://msdn.microsoft.com/en-us/library/ee308947(BTS.10).aspx

    http://msdn.microsoft.com/en-us/library/ee308947%28BTS.10%29.aspxhttp://msdn.microsoft.com/en-us/library/ee308947%28BTS.10%29.aspxhttp://msdn.microsoft.com/en-us/library/ee308947%28BTS.10%29.aspx
  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    39/79

    Page 39

    Microsoft Dynamics AX integration using Microsoft BizTalk Server

    By Ashish Mehndi, Consultant, Global Services, Microsoft

    Introduction

    Microsoft Dynamics AX is a global, adaptable business management solution that enables

    organizations to make business decisions with greater confidence. By automating and streamlining

    financial, customer relationship and supply chain processes, Microsoft Dynamics AX brings together

    people, processes and technologies, increasing the productivity and effectiveness of the business

    and helping to drive business success.

    In todays business environment all enterprises make extensive use of computer systems and

    applications in order to establish and maintain a competitive advantage. In order for these

    applications and systems to provide the desired advantage it is essential to ensure that the

    resources are available to all users and business processes that may benefit from the use. To ensure

    the same, these applications should be fully integrated to seamlessly flow the information across

    and pool the available resources to maximize the benefits. And here fits Microsoft BizTalk Server as

    a Business process management Server that enables companies to integrate, automate and

    manage Business processes.

    Enabling businesses to expose processes and data in real-time, BizTalk Server helps organizations to

    optimizebusiness processes, decreasing costs and eliminating inefficiencies. By providing simple

    yet powerful tools to gain a real-time understanding of business processes, BizTalk enables

    organizations to grow their business.

    This article focuses on how to integrate Microsoft Dynamics AX using Microsoft BizTalk Server. But

    before we dwell into the details of integration it is important to understand the features provided

    by Dynamics AX and BizTalk Server to integrate seamlessly and making sure that they have been

    installed appropriately.

    Microsoft Dynamics AX provides Application Integration Framework (AIF):

    Application Integration Framework (AIF) provides an extensible framework that supports multiple

    asynchronous transports, as well as synchronous transport using Web services, to reliably exchange

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    40/79

    Page 40

    documents in XML format with trading partners or other systems. An exchange starts with a

    document, that is, a document class defined using Microsoft Dynamics AX business logic. The

    document is serialized into XML and header information is added to create a message, which may

    then be transferred into or out of your Microsoft Dynamics AX system (called the local endpoint

    within AIF). The other entity taking part in the exchanges is called the endpoint.

    Microsoft Dynamics AX Adapter provided by Microsoft BizTalk Server:

    BizTalk adapters extend the functionality of BizTalk Server, enabling it to connect to other servers,

    applications and Web services. Specifically, they remove the need to develop infrastructure

    components such as network protocol support and translation, data conversion, data

    transformation, in the development of business process automation solutions. BizTalk Server

    adapters are "no-code" connectivity solutions, and are provided in-box with BizTalk Server.

    The Microsoft Dynamics AX Adapter for BizTalk can be installed on the BizTalk machine using theDynamics AX setup. After running the Dynamics AX setup on the BizTalk machine the following

    steps needs to be followed:

    1. On the Select installation type page, click Custom installation, and then click Next.2. On the Select Computer Role page, under Application integration gateway, select BizTalk

    adapter, and then click Next.3. On the Installing page, you can monitor installation progress as Setup proceeds.4. On the Completing Microsoft Dynamics AX Setup page, you can review the summary of roles

    installed on the computer.5. To exit the Microsoft Dynamics AX Setup wizard, click Finish.

    Customers use these adapters to connect these applications and automate processes that mayspan applications or organizational boundaries.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    41/79

    Page 41

    The Microsoft Dynamics AX Adapter for BizTalk Server supports both Inbound and outbound

    message processing.

    Inbound message processing: An external system sends a message through a BizTalk Server

    adapter. The AIF gateway receives service polls for messages and then brings them into the

    gateway queue. The AIF inbound processing service takes the messages from the gateway queue.

    Next, the business logic in the AIF document service processes the message and interacts with the

    internal Microsoft Dynamics AX database.

    Outbound message processing: The AIF outbound processing service processes send requests using

    the document services and places the outbound messages in the gateway queue. The AIF gateway

    send service then reads the messages from the gateway queue and sends them out using a

    transport adapter. These transports adapters include Microsoft Message Queuing (MSMQ), the file

    system, or other BizTalk Server adapter. The external system then receives the message from the

    appropriate transport.

    This article details on configuration operations related to the integration of Dynamics AX using

    BizTalk Server and covers both inbound as well as outbound message exchange. Further it also

    covers the basic guidance on where to look for errors in case of unexpected situations.

    Configuring Microsoft Dynamics AX Adapter for BizTalk

    Terminology

    This section explains the concepts used in the AIF.

    Term Description

    adapter A software component that enables messageexchange using a specific transport. In AIF, anadapter means a transport adapter.

    channel A named entity used to specify where and howto send and receive messages. A channelspecifies an adapter with its associatedconfiguration information and transportaddress.

    endpoint A company or entity that participates in abusiness-to-business (B2B) or application-to-application (A2A) data exchange. An endpoint

    can be an in-house independent system, in thecase of A2A.

    endpoint action policy Determines which actions are valid for aparticular endpoint. An action is bound to anendpoint using an endpoint action policy.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    42/79

    Page 42

    gateway queue Provides temporary storage for documents

    while they wait for processing. Inboundmessages are placed in a gateway queue byan inbound transport adapter. Outboundmessages wait in a gateway queue until anoutbound transport adapter picks it up forsending.

    message An individual unit of data transported betweenendpoint locations. A message consists of adocument plus a header containing informationabout the transfer.

    document class An X++ class (prefixed with Axd) with methodsthat perform actions on documents.

    pipeline processor The pipeline processor enablestransformations of the inbound/outbound XMLbefore/after the Microsoft Dynamics AXdocument class acts on the document.Components are provided in the base MicrosoftDynamics AX system for data valuesubstitution and XSLT documenttransformations.

    Web services A unit of application logic that provides dataand services to other applications that clientsinvoke by using the Simple Object AccessProtocol (SOAP) over the Hypertext TransferProtocol (HTTP). Web services can performfunctions ranging from simple requests tocomplicated business processes.

    Configuring Microsoft Dynamics AX Application Integration Framework (AIF)

    In order to integrate BizTalk with Microsoft Dynamics AX we need to configure the ApplicationIntegration Framework which acts as a bridge between the two. The following steps lists down thesteps to set up the Application Integration Framework which exposes data to BizTalk Microsoft

    Dynamics AX adapter.

    1. Start the Microsoft Dynamics AX client, and browse to the Basic Module (as shown below):

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    43/79

    Page 43

    2. Create the Local Endpoint or make sure that the Local Endpoint is configured:

    A local endpoint is the origination for sent messages and the destination for received

    messages. There may be more than one local endpoint, depending on how many companies

    are configured for your Microsoft Dynamics AX installation.

    a. Click Basic Setup Application Integration Framework Local endpoints.b. Press CTRL+N to create a new local endpoint record.c. Select a company from the Company field.d. Enter a name for the endpoint in the Local endpoint field.e. The name for the local endpoint should be representative of the Microsoft Dynamics

    AX company name that participates in the exchange.f. Press CTRL+S to save the data.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    44/79

    Page 44

    3. Configure an adapter

    The following adapters are available after installing Microsoft Dynamics AX:

    a. AifFileSystemAdapter

    b. AifMSMQAdapter

    c. AifWebServiceAdapter

    d. AifBizTalkAdapter

    Channels define the transport method that enables messages to move in and out of theframework to reach the endpoint. We need to configure adapter to use the channels in orderto enable messages reach the endpoint. To configure an adapter for use in a channel, youactivate it and specify its direction (inbound, outbound, or both) on the Transport adaptersform. Ensure that Transport Adapter is configured for AifBizTalkAdapter.

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    45/79

    Page 45

    a. Click Basic Setup Application Integration Framework Transport Adapters.

    b. Press CTRL+N to create a new transport adapter record.c. Select the AifBizTalkAdapter from the list of Adapter classes available.

    d. Enter a Name and make it active by selecting the Active checkbox (that is shown inthe above figure as A), so that it is available for use.

    e. The default value for AifBizTalkAdapter is Receive and Respond and this cannot bechanged (as AifBizTalkAdapter is used for both sending and receiving data betweenBizTalk and Microsoft Dynamics AX).

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    46/79

    Page 46

    4. Creating and configuring channels

    Channels define the transport method that enables messages to move in and out of theframework to reach the endpoint. Before configuring a channel, a transport adapter must beavailable.

    Channels may support inbound transfers only, outbound only, or both. Configuration settings

    are different depending on the direction for the transfer in the channel as well as for differentadapters. Inbound channels may use a response channel that handles verification or errorresponses to inbound transfers.

    a. Click Basic Setup Application Integration Framework Channels.

    b. Press CTRL+N to create a new channel.

    c. Select an adapter in the Adapter field.

    You must first have activated an adapter on the Transport adapters form before itappears in the list of available adapters.

    d. Enter the unique identification information for the new channel, including an identifier inthe Channel ID field and a friendly name in the Name field.

    a. Provide the channel ID as BizTalkChannel

    b. Provide the friendly Name as BizTalkChannel

    e. To activate the channel and allow it to participate in document exchanges, click Active (or

    A as shown in the figure).

    f. Configure the address for the adapter.

    a. Provide the address as BizTalkChannel

  • 7/29/2019 BizTalk HotRod Issue7 Q3 2009

    47/79