How to generate a BizTalk schema for a SAP Web Service

 

I have several clients who own a SAP system, so I often develop integration flows that invoke BAPI exposed as Web Service. However, every time, I lose a lot of time in verifying the SAP configuration that allowed me to download the correct WSDL and generate a XSD schema. So, I decided to document every step, from the access to SAP to check the correct configuration up to the necessary actions on BizTalk side.

 

Configure the SAP logon settings

 

Start the SAP GUI program

 

 

Add new connection entry

 

 

Select “User Specified System”

 

 

There are two ways to access the SAP system, in this document I choose to connect directly to the application server.

Then, specify a connection Description, Application server name, Instance number and System ID.

 

 

Accept default settings and click Next

 

 

Select your language

 

 

At the end you have the configuration ready to use.

 

 

Access to SAP

To access SAP, use an existing connection or one configured previously specifying user and password

 

 

You should get an interface similar to that shown below

 

 

So specify “soamanager” in the command field

 

 

The SOA Management web interface appears. Click on “Web Service Configuration”

 

 

Search the BAPI you want to generate a WSDL

 

 

Select the BAPI and click on “Apply Selection”

 

 

You must be sure that the “WSDL format” section is set to “Standard”. Unlike the wizard of visual studio will not be able to generate correctly the XSD schema and the bindings file.

 

 

Click on “Open WSDL document for selected binding or service”

 

 

The Internet browser appears with the WSDL. Save the file to a folder.

 

 

 

Open the BizTalk Visual Studio project and Add a generated items.

 

 

Select “Consume WCF Service”

 

 

Select “Metadata Files (WSDL and XSD)”

 

 

In the Metadata Files form, add the WSDL file that you had previously saved and then click Next

 

 

Specify a Namespace and click on Import

 

 

That’s all. You have your SAP web services schema ready to use.

 

Advertisements

Handling fault messages from Microsoft Dynamics CRM SOAP interface

 

Typically, what you do to integrate BizTalk directly with the Microsoft Dynamics CRM SOAP API is to:

 

  • Generate CRM artifacts;
  • Replace the schemas generated with those found in the CRM SDK.

 

These two simple actions, allow you to implement integration flow with CRM. In case of errors in the interfaces, the CRM is able to generate fault messages that can be very useful for identifying and solving problems. To make sure that BizTalk intercepts properly these messages you need to follow two additional steps.

 

To generate CRM artifacts

 

Right click the BizTalk project and choose Add then Add Generated Items

 

 

Select “Consume WCF Service”

 

 

Select “Metadata Exchange (MEX) endpoint

 

 

Specify CRM WCF endpoint in the following form:

 

http://<servername>/<instance_name>/XRMServices/2011/Organization.svc

 

 

Specify a namespace

 

 

Following you can see the result

 

 

To replace schemas

 

As is known, the XSD generated by the wizard is not correct, then you need to replace them with those made available by the CRM SDK (Microsoft Dynamics CRM Software Development Kit (SDK) for CRM Online and CRM 2013 (on-premises)).

 

Remove the generated schemas

 

 

Right click the BizTalk project and choose Add then Existing Item

 

 

Browse the folder where you have unpacked the CRM SDK package, go into the “SDK\Schemas\CRMBizTalkIntegration” folder, select the schemas with the name that starts with “organizationservice” and click Add.

 

 

To catch CRM fault message

To make BizTalk intercepts fault messages generated by Dynamics CRM, you need to act on the configuration of the WCF service of CRM and the type of fault message defined on BizTalk side.

 

Locate the web.config WCF endpoint of Dynamics CRM.

 

 

Modify the section “system.serviceModel” inside the web.config.

 

Original Vesion

 

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

 

New version

 

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

 

From visual studio, open the orchestration generated by WCF service consuming wizard. From orchestration view, add a new multi-part message type

 

 

Optionally rename the object

 

 

Specify BTS.soap_envelope_1__1.Fault as message type. You can find this schema in the Microsoft.BizTalk.GlobalPropertySchemas assembly

 

 

 

Expand the port types, select the port generated by the WCF service consuming wizard and, for each operation, change the message type of the fault message, as shown below.

 

 

Troubleshooting SAP connectivity

I often develop integration flows that interact with SAP and sometimes I happen to have connectivity problems for many different reasons.

Every time, I start from scratch to make troubleshooting so I decided to write a memo that I hope will be useful to others too.

 

·          First of all, try to restart the receiving host. Sometimes occurs that some configuration change and the BizTalk host need to be restarted.

 

·          To isolate possible problems related to wrong schema, configure a receive location with passthru pipeline and create a send port that subscribes that port. Shutdown any other port or orchestration that subscribe the same receive port.

 

·          Unicode vs non-Unicode. Make sure that the SAP system is aligned with the versions of the DLLs of the SAP client you are using.

There are in fact a version of Unicode and non-Unicode one of the following DLLs:

 

·          icudt34.dll

·          icuin34.dll

·          icuuc34.dll

·          librfc32.dll

·          librfc32u.dll

·          librfc32u.lib

·          libsapu16vc80.dll

·          libsapu16vc90.dll

·          libsapucum.dll

·          libsapucum.lib

·          mfc71.dll

·          mfc71u.dll

·          msvcp71.dll

·          msvcr71.dll

·          saprfc32.lib

 

On SAP side, check the RFC destination configuration:

 

clip_image002[8]

 

·          If the problem is not resolved, you must enable the detailed log on the WCF layer. For more details refer to the following site http://msdn.microsoft.com/en-us/library/cc185440(v=bts.10).aspx

 

Additional resources

 

http://help.sap.com/saphelp_nw04/helpdata/en/22/042f73488911d189490000e829fbbd/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/22/042f80488911d189490000e829fbbd/content.htm

 

 

BizTalk, RabbitMQ and JSON

In recent weeks, I happened to integrate RabbitMQ with BizTalk Server 2013. Great, I thought, there is a magnificent TechNet article that explains how to do it.

Too bad that I had to communicate using Json.

Anyway, Eventually I succeeded, but with some customization that I want to share.

The step to follow are four:

 

1.     Follow the article http://social.technet.microsoft.com/wiki/contents/articles/7401.biztalk-and-rabbitmq.aspx to configure all the components

2.     Customize RabbitMQ .Net Client

3.     Follow the article https://pellitterisbiztalkblog.wordpress.com/2014/05/05/send-and-receive-json-formatted-message-with-biztalk-server/ to Implement a custom pipeline component to receive e send Json messages

4.     Configure the send and receive ports

 

To customize RabbitMQ .Net Client

 

Open the solution and modify “rabbitmq-dotnet-client-3.2.1\projects\wcf\RabbitMQ.ServiceModel\src\serviceModel\RabbitMQInputChannel.cs” file.

In particular, find the “Receive” method and change the following highlighted line of code:

 

clip_image002

 

With the following:

 

 

var ms = new MemoryStream(msg.Body);

var bodyString = Encoding.UTF8.GetString(ms.ToArray());

 

System.Diagnostics.Debug.Write(bodyString);

 

bodyString = String.Concat(@”<s:Envelope xmlns:s=””http://www.w3.org/2003/05/soap-envelope”&#8221; xmlns:a=””http://www.w3.org/2005/08/addressing””><s:Header><a:MessageID>urn:&#8221;, Guid.NewGuid().ToString(), “</a:MessageID></s:Header><s:Body>”, System.Web.HttpUtility.HtmlEncode(bodyString), “</s:Body></s:Envelope>”);

 

System.Diagnostics.Debug.Write(bodyString);

 

ms = new MemoryStream(Encoding.UTF8.GetBytes(bodyString));

 

Message result = m_encoder.ReadMessage(ms, (int)m_bindingElement.MaxReceivedMessageSize);

 

 

Then, find the “Open” method and change the following highlighted line of code:

 

clip_image004

 

With the following:

 

 

string[] uriParser = base.LocalAddress.Uri.PathAndQuery.Split(“/”.ToCharArray());

 

// Create a queue for messages destined to this service, bind it to the service URI routing key

string queue = m_model.QueueDeclare(uriParser[uriParser.Length – 1], true, false, false, null);

 

 

To configure the send port and receive location

 

Following screenshots of the configuration to be applied to the ports.

 

Send Port:

 

clip_image005

 

clip_image007

 

clip_image009

 

Receive Location:

 

clip_image010

 

clip_image012

 

clip_image014

 

 

Receive messages from DB2 AS/400

Well, in a technological age in which everyone is talking about Cloud, Windows Azure and BizTalk Services, it seems strange to talk about AS/400, but at least in Italy there are still many installations and I found few example of its use with BizTalk Server.

This article shows how to implement a simple receiving flow from AS/400 system to a target system. The example shown below reports the steps for installing the necessary components, to apply a basic configuration to a receiving port and to generate the message schema that you will receive from the AS/400.

Additional artifact such as target systems schema messages, maps or orchestration I take them for granted.

 

Components Setup

From the Microsoft Host Integration Server 2013 cd run setup.

On License Agreement screen select “Yes, I accept the Items…” and click Next.

 

clip_image002[11]

 

On Usage Reporting Settings page make a selection and click Next.

 

clip_image004[9]

 

On Component Installation screen select at least the components shown below and click Next.

 

clip_image006[9]

 

clip_image008[9]

 

Then click on Install.

 

clip_image010[9]

 

Create Port and Packages

From BizTalk Server Administration console create a new port.

 

clip_image011[9]

 

Specify the typical port properties

 

clip_image013[9]

 

clip_image015[9]

 

clip_image017[9]

 

Select DB2 adapter and click Configure. Build the connection string as first step.

 

clip_image018[9]

 

The wizard starts.

 

clip_image019[9]

 

Select DB2/AS400 as data source platform.

 

clip_image020[9]

 

Specify the AS/400 Network Name o IP address and a port number.

 

clip_image021[9]

 

Specify at least the initial catalog, the package collection and the default schema.

 

clip_image022[9]

 

Choose the international locale settings.

 

clip_image023[9]

 

Then write the credentials.

 

clip_image024[9]

 

To receive data from AS/400 is enough select the following advanced options.

 

clip_image025[9]

 

On the review the connection properties page click Next.

 

clip_image026[9]

 

On the Validation screen click on Packages to generate package on AS/400 library.

 

clip_image027[9]

 

The connection string is composed. Now we have to specify the SQL Command.

 

clip_image028[9]

 

Specify a SQL Command statement.

 

clip_image029[9]

 

Note. To write and test SQL statement, typically I use Microsoft SQL Server Management console configuring a linked server to AS/400 system.

 

Now you have to specify “Document Root Element Name” and “Document Target Namespace” properties.

 

clip_image030[9]

 

Generate Schemas

There are two option to generate AS/400 inbound schema:

 

·         Use thewizardfrom Visual Studio(this notalwaysgeneratesa schemethat works)

·         Activate the AS/400 receive port and write the output instance on a folder. Then using XML well formed generation schema to import the schema.

 

First option:

From Visual Studio start Add Generated Items wizard.

 

clip_image032[9]

 

Choose Add Adapter Metadata.

 

clip_image034[9]

 

Select DB2, then select the port created in the previous step.

 

clip_image035[9]

 

Select the existing connection string.

 

clip_image036[9]

 

Specify the same target namespace and root element name, chosen during port creation.

 

clip_image037[9]

 

Then select the statement type (select statement in my case).

 

clip_image038[9]

 

Specify the select sql script that the receive port will execute.

 

clip_image039[9]

 

Now you have your AS/400 schema

 

clip_image040[9]

 

Second option

From BizTalk Administration console, open the AS/400 receive location properties window an select (temporary) the PassThuReceive pipeline.

 

clip_image042[9]

 

Then create a send port.

 

clip_image044[9]

 

On the Filters tab, specify BTS.ReceivePortName equal to SampleQuery. This allow you to write messages coming from AS/400 in a folder.

 

clip_image046[9]

 

Enable both receive location and send port. In the destination folder you will find an instance of message coming from AS/400 system.

Now, from Visual Studio you can use that instance to generate a schema.

 

clip_image048[9]

 

Select Well-Formed XML and specify the generated file.

 

clip_image049[9]

 

So you have your schema.

 

clip_image051[9]

 

Ordered Delivery option just to serialize calls

Most of the integration scenarios includes database systems among the interlocutors.

If the database is not large, and contains a simple architecture of entities, develop interfaces is not so difficult.

Otherwise, if the architecture of entities and relationships is very complex and the occupation of space is hundreds of GB, it might be more difficult to write interfaces.

In this scenario, you can find thousands of tables, views, stored procedures with hundreds of lines of code and functions.

In these contexts, often we not even have visibility of the services that we going to call, and the risk of generating dead lock on tables is extremely high. This risk could increase, especially in the case of use of techniques such as message de-batching where BizTalk Server generates multiple thread with a perfect parallelism.

To overcome this, if you don’t have the opportunity to act within the stored procedures correcting the architecture of the lock, it is possible to enable the “ordered delivery” option on the WCF send port.

“When the port bound to the transport is marked for ordered delivery, then BizTalk Server enforces ordered delivery by ensuring that the transport does not get the next outbound message until the current one has been successfully sent. To achieve this, BizTalk Server passes each message to the transport’s adapter in a single batch and waits until the adapter has successfully deleted the message from the message box before delivering the next message, in another batch, to the adapter.”

Obvious that this is only an extreme measure and it is advisable to apply it only if is acceptable for the process, serializing the calls to the database, that even if they occupy a very small percentage of the whole process, still represent a bottleneck.

Polling Oracle Database Using Stored Procedures, Functions, or Packaged Procedures and Functions

 

This document shows the step to configure a polling operation using Oracle Function or Packaged Procedure and Functions.

Please refer to MSD article for additional detail (http://msdn.microsoft.com/en-us/library/dd788064.aspx).

Procedure

Open Visual Studio, create a new BizTalk project and generate the polling schema using Consume Adapter Service wizard.

clip_image002

Click on “Configure”.

clip_image003

Specify a PollingId as Polling Unique Identifier.

clip_image004

Leave the following form with default settings.

clip_image005

Connect to the database, select “Service (inbound operation)” and choose the Oracle function.

clip_image006

Edit binding file in order to set the following properties:

1. Receive port name

2. Receive location name

clip_image007

3. If BizTalk host is Trusted you should set host trusted equal to true.

clip_image008

From BizTalk Administration import the generated binding file.

clip_image009

If needed, rename the receive port and enable routing for failed messages.

clip_image011

Rename the receive location.

clip_image012

Click on Configure and set the following properties:

PolledDataAvailableStatement

In this example, we use the Oracle function CCM_ADT_PKG.CCM_COUNT, which require a string parameter.

SELECT CCM_ADT_PKG.CCM_COUNT('A02') FROM DUAL

PollingAction

From Visual Studio open the schema “schOracleA02CCM.PollingPackage.CCM_ADT_PKG.xsd” and find for the “action” element.

clip_image013

Copy the url “http://Microsoft.LobServices.OracleDB/2007/03/CCM/PollingPackage/CCM_ADT_PKG/CCM_BIZTALK_ADT_2” and set the PollingAction property.

PollingStatement

From visual studio, generate a XML instance for the schema “schOracleA02CCM.Package.CCM_ADT_PKG.xsd”.

clip_image014

Modify XML content setting up the right parameters.

<ns0:CCM_BIZTALK_ADT_2 xmlns:ns0="http://Microsoft.LobServices.OracleDB/2007/03/CCM/Package/CCM_ADT_PKG">
    <ns0:TIPO_MESSAGGIO>A02</ns0:TIPO_MESSAGGIO>
    <ns0:FL_ELABORAZIONE>0</ns0:FL_ELABORAZIONE>
</ns0:CCM_BIZTALK_ADT_2>

Set Polling Interval to 30 seconds and user name and password.

clip_image015