Tuesday, September 24, 2013

Compensation block


Scope: Scopes are used for three reasons:

  1. to configure transaction (long running or atomic)
  2. to handle exceptions
  3. to trigger compensating logic


A scope shape can have one or more Exception handling blocks and one Compensation Block. The Transaction type you've chosen for your scope will define which of these blocks can be added. An atomic scope can only have a compensation block, and a scope configured with the transaction type none can only have an Exception block. While a long running scope can have both blocks.

For an overview of the possibilities, check the below screenshot.



There could be more than one Exception block, but only one Compensation block added to a Scope.


Compensation block
Compensation is a way to correct or undo logical piece of work that have previously committed. 
       An exception can occur in the orchestration after successfully executing all logic in the scope. In this case, the process might be in a state where it is logically incorrect. So the action already performed in a transnational scope need to be compensated... this can be achieved using a compensation block
If no compensation block is added, the default compensation will be performed. this means calling all compensation blocks of the nested scopes, starting with the most recently completed ones, just as with the default exception handler.

Compensations blocks may be created for both atomic and long running transactions.  Compensation blocks must be explicitly invoked. To invoke the Compensations block, finally drop the "Compensate" shape into the exception handler block (Compensate shape can be placed only in exception or compensation block) and set the "Compensation" property to the corresponding transaction name in the properties window.

A particular scope can be compensated only once.The compiler will prevent more than one path leading to the compensation of a particular scope.

Compensate
      The compensate shape can only be used inside of an exception handler. The explicit use of this compensate shape, allows us to specify the order of compensation execution ourselfs. So this can be used in cases the default order (starting from te most recently completed ones and working its way back) doesn't fit.
1 compensate shape can only trigger 1 compensation block of a transaction. So the order must be defined using multiple compensate shapes, calling the compensation blocks in the desired order.




When an Atomic transaction throws an exception, this will generally be caught at an outer non-atomic scope. Atomic scopes cannot have exception handlers of their own. Compensation can only be invoked if the exception is caught by an outer LongRunning transaction.

For Ex:
Image
Consider the above scenario for basic compensation model

We have 1 LongRunning transaction and 3 nested atomic transactions which insert data in DB with their compensation blocks associated with them,now the 3rd atomic transaction fails to commit then it invoke the compensation block in backward direction .

Execution order:

Insert into Table1(scope Shape)
Insert into Table2(scope Shape)
Insert into Table3(scope Shape) —  not commited
Catch exception
Compensation block 2
Compensation block 1

Thursday, September 19, 2013

What are the different types of transactions available for orchestration?

A scope with no transaction is usually used as a try/catch block just to handle exceptions.

BizTalk Server supports two distinct types of transactions: atomic and long-running.

     Transactions are implemented in Orchestrations using Atomic Scope. An Atomic Scope supports ACID properties of Transactions where as Long Running Scope Supports C&D (Consistency and Durability) properties of ACID.



AtomicAn atomic scope cant be placed within a Normal Scope.
There are two other Advantages of Atomic scope in addition to supporting Transactions.

1. Non-Serializable classes can be called from an Atomic Scope.

2. The number of Persistence points within an Orchestration can be reduced as an atomic scope will always induce one Persistence point (at the end of the scope).

Long running:  A business process that might take seconds, minutes, or even days or weeks to complete. This is when a long-running transaction is more suitable.

Wednesday, September 11, 2013

Enlist Vs UnEnlist (State information about BizTalk Server artifacts)

BizTalk Server has many artifacts such as send ports, send port groups, receive locations, parties, and orchestrations. Of the artifacts, send ports, send port groups, and orchestrations  have a state, which determines whether the artifact can process messages.

We have four variants with messages received by adapter :

1).  After Subscriber is Enlisted and Started, the messages come to the Message box and then routed to the Subscriber.
2). After Subscriber is Enlisted but not Started yet, the messages are waiting inside Message box in the Suspended (Resumable) state. When Subscriber is started, those messages go out from Message box to this Subscriber.
3). If the Subscriber is not Enlisted, and the message type in well-known by BizTalk, we'll get error
Description:
The Messaging engine failed to process a message submitted by adapter:{adapter details}. Details:Could not find a matching subscription for the message. This error occurs if the subscribed orchestration schedule or send port has not been started, or if some of the message properties necessary for subscription evaluation have not been promoted. Please refer to Health and Activity Tracking tool for more detailed information on this failure
It means the message was recognized by BizTalk, because BizTalk knows of its type. But there is no one subscription to this message.

UnEnlist:- Remove subscription information from Message Box.
Stop:-Will not Remove Subscription information form message box but the port or orchestration will not process(send) messages.
Enlist:-Write Subscription information into message Box(Bound).
Start:-Process(send) messages.

Don't confuse with Stop and Enlist
the "Stop" changes the state from "Started" to "Stopped/Enlisted". 
the Enlist will move from Unenlisted to "Stopped/Enlisted" state.

Ex:
you have a mailbox at the local post office.  When you go out of town on vacation, you drop from the "Started" to the "Enlisted" state.  They hold your mail for you, and when you return, they give you the box full of mail.  When you move out of town (or are tired of all the junk mail), you "Stop" your mail and they post master marks it as undeliverable.

Friday, September 6, 2013

InternalServiceFault - The value of a promoted property cannot exceed 256 characters. Property "Action" Namespace "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties".


I tried to invoke a WCF service from within an orchestration and got the below fault message in response


<Fault xmlns="http://www.w3.org/2003/05/soap-envelope"><Code><Value>Receiver</Value><Subcode><Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</Value></Subcode></Code><Reason><Text xml:lang="en-US">The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug&gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.</Text></Reason></Fault>

after IncludeExceptionDetailInFaults = ture got below exception.

<Fault xmlns="http://www.w3.org/2003/05/soap-envelope"><Code><Value>Receiver</Value><Subcode><Value xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</Value></Subcode></Code><Reason><Text xml:lang="en-US">The value of a promoted property cannot exceed 256 characters. Property "Action" Namespace "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties".
Parameter name: obj</Text></Reason><Detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true" /><InnerException i:nil="true" /><Message>The value of a promoted property cannot exceed 256 characters. Property "Action" Namespace "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties".
Parameter name: obj</Message><StackTrace>   at Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkServiceInstance.EndOperation(IAsyncResult result)
   at Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkServiceInstance.Microsoft.BizTalk.Adapter.Wcf.Runtime.ITwoWayAsync.EndTwoWayMethod(IAsyncResult result)
   at AsyncInvokeEndEndTwoWayMethod(Object , Object[] , IAsyncResult )
   at System.ServiceModel.Dispatcher.AsyncMethodInvoker.InvokeEnd(Object instance, Object[]&amp; outputs, IAsyncResult result)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeEnd(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage7(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage6(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><Type>System.ArgumentOutOfRangeException</Type></ExceptionDetail></Detail></Fault>


The problem was solved.
In my case WCF service (logical)port operation name from orchestration was not equal with operation name in physical port binding properties.

or 

Go to send port -> Configure and SOAP Action Header section.
Remove below lines

<BtsActionMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Operation Name="OperationXXXName1" Action="OperationXXXName1" />
  <Operation Name="OperationXXXName2" Action="OperationXXXName2" />
</BtsActionMapping>

And keep only one action in the SOAP Action Header section. (i.e OperationXXXName1).


Thursday, September 5, 2013

WCF-BasicHttp - ActionNotSupported


Last 4 hours I was hanging with the below error while testing my BizTalk Orchestration to send an request message to External wcf Service.

<s:Fault xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">The message with Action '{service url}' 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).</faultstring></s:Fault>



Fix is very simple, we have to update the Action value in configure->general-> Action section

In order to integrate external WCFServices in BizTalk, both Schemas have to match.
If the External WCFService schema does not match the BizTalk schema, BizTalk will not be able to send the request. 

WCF adapter tries to match the operation name with an action defined in the BtsActionMapping, and if it can't find the Operation context property in the BTS message, it'll throw exception.


Another thing you can look at is the ENDPOINT properties... and make sure all parameters are properly set.

A good test is to use a Soap Tool to test your External WebService. You can try SoapUI tool
add your service to the SOAPUI and verify the operation action actions in the below shown screen.



if the BtsActionMapping is different, please update latest in the properties and verify. it'll fix the issue.