Thursday, January 29, 2015

Title: BizTalk for Archiving / Backup:
Author: Toraj Khavari
Date: January 29 2015
Objective: The Microsoft BizTalk has a suite of powerful technologies and tools. It can support artifacts archive and backup requirements. I had a business requirement to archive any document received and sent to the A-dec’s vendors. How to use BizTalk to archive source and destination files? Let us explore answers together.

Article Body: Although, BizTalk can support any source and destination documents, and web services formats, in this article, we will explore solutions to archive inbound and outbound EDI text files. The BizTalk SFTP (Secure File Transfer Protocol) adapters are used to communicate across secured firewalls to and from Azure MFT (Managed File Transfer) Server. To setup BizTalk SFTP, refer to my previous wiki article “Biztalk SFTP Adapter Configuration.

Business Requirement: Archive all the Inbound and Outbound artifacts from and to a vendor.

In this case, the file structure in the MFT servers were implemented as follow. However, the archived files can be anywhere.

First let us implement a solution to archive Inbound, from vendors or customers, to A-dec. The vendors or customers are the source of information and A-dec is the destination. In other words, in this example, archive all …ESPInbound data to …Archive/ESPInbound without effecting the existing maps, schemas, and orchestration.

1-      A) Add a Send after the Receive in the Orchestration, B) match the Message with the Orchestration Received Message, C) configure a Send Port, and D) connect the Send to Send Port.


2-      In the BizTalk Admin tool, after configuring the port, the Filters will be of great value to us. Implement the archive rules in the port Filters. Example, as follows.


3-      The Parties rules are important. Make sure the new archived folders are added to the parties.


Second, let us implement a solution to archive Outbound, from A-dec to vendors or customers. A-dec is the source of information and vendors or customers are the destination. In other word, in this example, archive all …ESPOutbound data to …Archive/ESPOutbound.

1-      Archiving information must be strategically placed in the BizTalk Orchestration. It must be done after posting the outbound message, successfully. A) Add a Send after the Send in the Orchestration, match the Message with the Orchestration send Message, B) configure a Send Port, and C) Connect the Send to Send Port.


2-      Send port’s filters and Parties Send Ports will play important roles. Set the rules to meet the business needs.

Hints:
-          Although BizTalk Orchestration makes development, debugging and production support easier, it is not a requirement. Standard send port and Outbound Maps and filters can meet the need, too.
-          There are other technologies, e.g., file watchers, scheduled batch scripts, cascade file copy, etc. to duplicate files. They all have advantages and disadvantages. I believe, BizTalk added send ports are clean, reliable, traceable, fault tolerant, and we do not have to bring another technology in house.
-          Azure Servers and all production servers have scheduled archive and backup strategies.  Beyond duplicating artifacts with BizTalk, it is advantages to rely on servers archive and backup technologies.
-          The added send ports have no effect on orchestration’s maps, schema, etc.

The BizTalk Ports and Adapters support flexible and scalable archive and backup strategies. Use them appropriately. However, rely on other technologies for standard servers’ archive and backup.

Happy coding, Toraj

References:

-          BizTalk SFTP Adaptor Configuration - https://team.a-dec.com/sites/SolDev/Developer%20Wiki/Biztalk%20SFTP%20Adaptor%20Configuration.aspx or http://torajkhavari.blogspot.com/2015/01/title-biztalksftp-adaptor-configuration.html

Version 1.0.0129.02
Title: Biztalk SFTP Adaptor Configuration:
Author: Toraj Khavari
Date: January 29, 2015 – Version 1.0.2529.01

Objective: The Microsoft Biztalk out of the box supports Secure File Transfer Protocol (SFTP). The SFTP adapter is a great technology to communicate information across corporate firewall securely via internet. An introduction to Biztalk SFTP configuration is my objective.

Article Body:  In this article we explore how to configure Biztalk SFTP for external partner inbound and outbound ports. Let us start with some basic principles and standards.
-          When you are designing Biztalk communication with external servers and services, minimize A-dec’s (company) risk with a few fundamental best practices.
o   Empower A-dec BizTalk adaptors to Get and Post information. Minimize, or better limit, external companies putting information inside A-dec firewalls.
o   Use Biztalk SFTP anywhere possible. The need for SSL and A-dec firewall compromise will reduce by using SFTP.
o   Keep A-dec Security coordinators and Support Services, in the loop for any external FTP.
o   If the A-dec external partners select FTP protocol with Secure File Transfer Protocol Server, consider utilizing encryption and decryption technologies and protect the information at source.
o   A-dec has a rich set of encryption and decryption assemblies. If the posted information is sensitive, in addition to using SFTP, use the encryption and decryption technologies.
-          An A-dec external partner inbound port is an A-dec post (e.g., EDI 850 Purchase Order (PO) to a vendor).
-          An A-dec external partner outbound port is an A-dec get (e.g., EDI 856, Advance Shipping Notice (ASN) from a vendor, EDI 810 Invoice from a vendor).
-          A-dec may select to communicate using SFTP. The partners have the freedom to communicate using other protocols (e.g., FTP). The partners’ decision has no effect on A-dec’s choice and vice versa.
In my case, I have multiple vendors, W&H Dentalwerk® and East Side Plating® (ESP). Each vendor partner has its own dedicated Inbound and Outbound port in the Management File Transfer (MFT) Server. The A-dec Biztalk SFTP adaptor securely communicates with the MFT server without any Firewall compromise or custom SSL setup. In this article, we will focus on W&H Dentalwerk, Also Known As (AKA), WH, WandH and W&H. To have a comprehensive end to end testing, WHReceived and WHSend ports are created in the A-dec Biztalk Server. The following diagram will describe the top-level architecture, pictorially.

The A-dec PO to W&H Partner can place in the WHRecived and Biztalk will map, orchestrate, and post it in the WHInbound. The W&H ASN and Invoice can be placed in WHOutbound. Thereafter, Biztalk will get the source file, map, orchestrate, and place it in WHSend.

Hints
-          I have selected File adaptors for WHRecived and WHSend for simplicity. You can select any Biztalk adaptors to meet you requirements, such as, WCF*, MSMQ, POP3, SMTP, SQL etc. The adaptors can support Dynamics AX Application Interface Framework (AIF), SharePoint Services, Databases, and the list goes on.
-          To properly configure and test the SFTP adaptor, prepare as follows:
o   Have access to a tested MFT server. Have appropriate user account and password.
o   Install and setup your favorite file transfer and browser. In my case, I am using FileZilla and Putty.
o   Have a set of tested and ready Biztalk Schema and MAP for Inbound and Outbound Orchestrations.
o   Have a few inbound and outbound data source files.
o   MFT Servers come in different operating systems, Windows, UNIX, and Linux. Biztalk SFTP syntax and semantics will accommodate them. The MFT operating system will have minimal impact on the SFTP configuration.
o   Do not surprise your security czar, if you are going outside A-dec. Let them know what you are doing.

Biztalk SFTP Configuration

Let us start with information orchestration between WHReceived and WHInbound. The A-dec Posts W&H PO.
1-      Start the Microsoft Biztalk Admin tool.

2-      Create a Static One-Way Send Port > Select SFTP Adaptor Type > Press the Configuration Button > Complete the SFTP Transport Properties > Select Apply > OK > Select the appropriate Send handler and Send Pipeline > Apply > OK.
The standard SFTP is a very secure communication. However, if you insists to have your own SSH Host Key, set the AcceptAnySSHServerHostKey to False, generate a SSH Key Finger Print between MFT server and SFTP adaptor, and copy the key in the SSHServerHostKeyFingerPrint.

It is a good practice to use the MFT Server Domain Name System (DNS) instead of IP Address. It will provide a layer of separation and fits in the Service Oriented Architecture (SOA) model, nicely.

3-      Setup the Biztalk Filter for the Send Port. You can use any of the Filters’ Property to meet your requirements. For now, I just point it to the receive port name. Select Apply and OK.


4-      Create the One-Way WHInternalReceive Port. 1- Select Receive Ports > 2- New > 3- One-way Receive Port > 4- General Tab Name is WHInternalReceive > 5- Select Receive Locations > 6- New > 7- General Tab Name is WHInternalReceiveLocation > 8- Select File Adaptor > 9- Select Configure button > 10- Configure the File Transport Properties > 11- Select the desired Receive handler and pipeline > 12- Apply and OK.  


5-      At this point the receive port requires a map to orchestrate the information. Navigate to the Inbound Maps for the Receive Port and select the Biztalk deployed Source Document, MAP, and Target Document.


If you do not see your maps, check the deployment script and your Biztalk solution Maps in the Applications folder in the Biztalk Admin tool.

At this point, we have all the needed connections to meet the WHReceived and WHInbound orchestration. Start the WHSFTPRaceSpaceInbound and WHInternalReceiveLocation.

Hints:
-          The WHSFTPRaceSpaceInbound URI must have “//” (two “/”) between the MFT server name and the partner folder path.


-          The WHInternalReceiveLocation URI must point to A-dec internal server.


-          The WHSFTPRaceSpaceInbound  and WHInternalReceiveLocation status must be green.

Let us start with the information orchestration between WHOutbound and WHSend. The W&H Posts A-dec’s ASN and Invoice in the WHOutbound port. Thereafter, Biztalk gets the information and orchestrates it to the WHSend port. There are some similarities between the WHOutbound and WHSend orchestration and WHReceived and WHInbound. Therefore, I omit the duplicated instructions.

1-      Create a new EDIWHSFTPRaceSpaceReceive Receive Port using Biztalk SFTP adaptor.

There no maps required.

2-      Create a new Send Port, EDIWHSend, and configure it.


3-      Utilize the Send Port’s filter to identify the partner. The Partners information configured in the Biztalk Admin tool’s Parties services.


At this point, you can start the EDIWHSFTPRaceSpaceReceive and EDIWHSend ports.

The entire Biztalk configuration is completed. Henceforth, utilize FileZilla post information and watch for Biztalk orchestration result set.

Lessons Learned:
Although I have imbedded a lot of my lessons learned in the above instructions, let me share with you a few more.

-          If you run into “Microsoft.BizTalk.Adapter.SftpInvoker.SftpException: Open SFTP connection error.” before changing the AcceptAnySSHServerHostKey to False, and entering SSH Server Host key, I recommend the following.
o   Use your favorite FTP tool, FileZilla or Putty, try to copy file between source and destination folders. During this process, any security violation will become apparent.
o   The issue usually is Read, Write, and Execute credential. After credential changes, the Biztalk 2013 SFTP adaptor works fine.
-          Biztalk Event log and Suspended query are great resources. Use them.
-          Biztalk Suspended query does not capture all the security and SFTP errors. Use the Biztalk Event log.

Have fun with Biztalk. It has come a long way. A few years ago, we had to add code to handle SFTP. Now the Biztalk 2013 version bundles enhanced SFTP adaptors in the standard install.

Cheers, Toraj

References:
2.      EXPLORING THE OUT-OF-THE-BOX SUPPORT FOR SFTP IN BIZTALK SERVER 2013, http://blog.quicklearn.com/2013/07/26/exploring-the-out-of-the-box-support-for-sftp-in-biztalk-server-2013/
3.      How to view the fingerprint of the ssh host key,  http://www.enricozini.org/2008/tips/ssh-host-key-fingerprint/

Special thanks to James Ward and his assistance during this assessment, his continuing support, and dedication.


Title: BizTalk 2013 and AX2012 R2 Receive Services Interface:
Author: Toraj Khavari
Date: January 29 2015

Objective: Use the Microsoft BizTalk’s Send ports to interface with Microsoft Dynamics AX 2012 R2 Application Interface Framework (AIF) receive services. No file drop, directly uses the AX services.

Article Body: Microsoft Dynamics AX AIF services support files drop and direct web service interfaces. BizTalk can support file drops to communicate with Dynamics AX. Interface with the AIF services directly, unwaveringly, have significant advantages. Such as, no need of file drop location, added file location security, disk storage, another server to depend on, etc. As long as the BizTalk server, Dynamics AX Application Object Server (AOS), and Network are available, we have interfaces.

When I started on the BizTalk and Dynamics AX R2 services interface, I had a steep learning curve. I encourage you to put the AX file interface knowledge behind you and look at the interface in a pure Service Oriented Architect (SOA) methodology. Let us review some basics together. All web services interfaces have fundamental Address, Binding, and Contract, also known as, ABC.
·         "A" stands for Address: Where is the service?
·         "B" stands for Binding: How do I talk to the service?
·         "C" stands for Contract: What can the service do for me?
Dynamics AX R2, and higher version, in addition to ABC take full advantage of the web services namespace. The namespaces uniquely identify a set of names so that there is no ambiguity when objects having different origins but the same names are mixed together.

1-      When you receive the Microsoft Dynamics AX AIF services URI, take your favorite browser, paste the URI in the address bar, and study the services. You can get the URI from the AX System Admin or start an AX GUI > Select System administration > Services and Application Integration Framework > Inbound ports (in my case). Find your service. Select it and verify that it is Active. Copy the WSDL URI.  E.g., in my case, the URI as follows.
http://<<Server Name:Port>>/DynamicsAx/Services/PurchInvoice810

I am interested in creating an invoice and using NetTcp BizTalk Adapter. Copy both information.

2-      Write a short C#, or your preferred language, project program and create the Microsoft Dynamics AX AIF services. Study the project’s configuration app.config file and take note of the “userPrincipalName”. You can add Service References to your project in Visual Studio. Select Project > Add Service Reference > Paste the AX Service URI in the Address field > Press OK.

Now that you have done your homework, let us focus on BizTalk project.

3-      Studying and understanding the Ax Services generated schemas are paramount for the next steps successful implementation. Take the time needed to discover the services provided. There are limited documentations available. Because, the AX services and ability to customize them are unbounded. If you invest time in this step, you will save yourself a lot of time for the subsequent steps, deployment, and debugging.
Add an Empty BizTalk Server Project to your solution. In my case, I called it “Adec.VendorsEDI.InboundAdecSchema”. The Microsoft Dynamics AX AIF services are rich and provide significant services. Add a sub folder “AXPurchInvoice810SvcSchema” in the “Adec.VendorsEDI.InboundAdecSchema” to collect all generated schemas in one folder. Select the “AXPurchInvoice810SvcSchema” folder > Right Mouse Click > Select Add Generate Items … > Consume WCF Service > Next > select Metadata Exchange (MEX) endpoint > Next > Paste the URI (step 1) in the Metadata Address (URL) Field > Next > Import. At this point the wizard adds a few schemas to the “AXPurchInvoice810SvcSchema” folder. Take a while and study the schemas. Start with Services schema and get a clear direction of the soap envelop and body constructions. My business requirements were around creating invoices, in this case. Therefore, I focused around Purchase Invoice Service Create Request and its Response.
Delete the default created Orchestration (.odx) file.

4-      Create the first map.  I refer to it as the web services soap’s “Body”. Use the standard BizTalk mapping technologies. However, the key and utmost importance is, use the correct and published schema created in step 3. There is no need of anything else, or other schemas.


5-      The web services require soap envelop. Create the envelop map using the standard BizTalk mapping technologies. The inbound schema, in this case, is the outbound of step 4. The outbound schema is the create service envelop. Use mass copy functoid and copy the entire inbound schema, soap’s “Body”.


6-      In the BizTalk orchestration create the Messages required. A) Cascade two Transform functoids to map the soap’s “Body” and “Envelope”, respectively. Outcome of step 4 and 5. B) Configure a send port and connect it to a Send functoid to expose the soap envelop with embedded body. The Dynamics AX services support request and response ports. I will leave the request and response port handling for another article.


7-      The send port Identifier will play an important role in the BizTalk. In my case it is called “CreateOperation”. No space and no special characters, Select the send port operation and take a note of your Identifier. It will be used in the BizTalk send port “Action”.


8-      At this point, the Visual Studio project is ready. Compile the solution and verify all the Schemas and Maps. Deploy the solution. Validate that the components are deployed in BizTalk, and the server’s GAC (Global Access Cache).

9-      Open the BizTalk Admin tool and the solution in the BizTalk Group. A) Add an WCF-NetTcp Send port. Select the Configure button. B) Copy and paste the Dynamic AX net.tcp UNI in the Address (URI). Result of step 1. C) Create an Action that reflect the Visual Studio orchestration send port Identifier (Result of step 7) and the desired Operation URI (Result of step 1).

<BtsActionMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <Operation Name="CreateOperation" Action="http://schemas.microsoft.com/dynamics/2008/01/services/PurchaseInvoiceService/create" />
</BtsActionMapping>

D) Select the Edit and enter the User Principal Name. The result of step 2.


10- I increased the WCF-NetTcp Binding timeouts and message size.


11- The Security worked for me only if the Security mode is set to “Transport”, The Transaction client credential type is “Windows”. The “EncyptAndSign” is selected for Transport protection level.  Dynamics AX has its own security. Make sure the User Principal Name and BizTalk runtime service ids are registered in the AX and have appropriate Dynamics AX security credential.


12- The WCF-NetTcp Messages is setup to Body. Apply and save the port.

13- Start the new WCF-NetTcp port and bind it to the Orchestration Outbound port. Start the orchestration.

14- Refresh the BizTalk application and restart the Host Instances.

The solution collection and BizTalk ports are ready for testing. Enjoy new discoveries and have fun debugging.

Hints:
-          Dynamics AX has History and Exceptions logs. Use them in addition to BizTalk events. They are great debugging resources. Start an AX GUI > Select System administration > Services and Application Integration Framework.

-          If you get the following error message, check the port’s Action.
Entity action cannot be specified. Or

‘cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).


-          If you see the following error message, check the envelope and body schemas. Most likely, incorrect schemas are used.
The value in field <<Schema Field>> is invalid. Or

Invalid document schema. The following error was returned:  The 'http://schemas.microsoft.com/dynamics/2008/01/documents/<<Schema Name:Node>>' element is not declared.

-          Do not waste too much time doubting the BizTalk Adapters and AX Services. When in absolute doubt, use Network sniffers to validate BizTalk and AX ports communications. There are a few free downloads available on-line.

-          The XML message between BizTalk and Dynamic AX are standard Soap messages. Nothing more or less. There is no need to add or take away from the published schemas. Example is as follows. I encourage you, forget about file drop communication with Dynamics AX, it will help you. Rely on pure soap and SOA.


The interface between BizTalk 2013 and AX 2012 R2 proves to be extremely rewarding.  At times, I wish error messages were more meaningful, and straight forward. The BizTalk and AX proved, once more to me, they are solid, scalable, reliable, and good technologies. I encourage you, if you ever faced system interface challenges, do not compromise and do not listen to unsubstantiated accusations. Learn the sand boxes. Significant knowledge and technologies are invested in the enterprise products such as BizTalk and Dynamics AX. SOA Works!

Happy coding, Toraj

References:
-          Introduction to Building Windows Communication Foundation Services - https://msdn.microsoft.com/en-us/library/aa480190.aspx
-          How to integrate Dynamics AX 2012 R3 AIF Document Service with BizTalk server – Very Good Reference - http://tech.alirazazaidi.com/how-to-integrate-dynamics-ax-2012-r3-aif-document-service-with-biztalk-server/
-          Walkthrough: Consuming WCF Services with the WCF-BasicHttp Adapter - http://msdn.microsoft.com/en-us/library/bb246019.aspx

Version 1.0.0203.01