title: BizTalk TPE continuations and uncompleted activities
body: <p>Within my BizTalk 2010 solution I have the following orchestration that’s is started by the receipt of a courier update message. It them makes a couple of call to AX's WCF AIF via two solicit-response ports, a Find request and an Update request.</p>
  
  <p><img src="https://i.stack.imgur.com/bAVLB.png" alt="enter image description here"></p>
  
  <p>For this application we are meeting audit requirements through use of the tracking database to store the message body. We are able to link to this from references provided in BAM when we use the TPE. The result for the customer is nice, they get a web portal from which they can view BAM data of message timings etc. but they can also click a link to pull up a copy of the message payloads from the tracking db. Although this works well and makes use of out-of-box functionality for payload storage it has led to relatively complex jobs for the archiving of the tracking db (but that's another story!). </p>
  
  <p>My problem relates to continuation. I have created the following Tracking Profile:</p>
  
  <p><img src="https://i.stack.imgur.com/AvDsJ.png" alt="enter image description here"></p>
  
  <p>I have associated the first of the orchestration's two solicit response ports with the continuation RcvToOdx based on the interchange Id and this works, I get the following single record written to the Completed activity table:</p>
  
  <p><img src="https://i.stack.imgur.com/yDThl.png" alt="enter image description here"></p>
  
  <p>So, in this case we can assume that an entry was first written on receipt in the inbound message, with the TimeReceivedIntoBts column populated by the physical file receive port. The FindRequestToAx column was then populated by the physical WCF send port. Because this was bound to the RcvToOdx continuation Id and used the same interchange Id and the previously mentioned file receive message, the update was made to the same activity. Notification of the resulting response was also updated to the same activity record - into the FindResponseFromAx column.</p>
  
  <p>My problem is that I would also like BAM to record a timestamp for the subsequent UpdateRequestToAx. Because this request will have the same interchange Id as the previous messages I would expect to be able to solve this problem by simply binding the AxUpdate send port (both send and receive parts of it) to the same continuation id, as seen in the following screen grab:</p>
  
  <p><img src="https://i.stack.imgur.com/20LU3.png" alt="enter image description here"></p>
  
  <p>I also map the UpdateRequestToAx milestone to the physical Ax_TrackAndTraceUpdate_SendPort (Send) and the OrchestrationCompleted milestone to Ax_TrackAndTraceUpdate_SendPort (Receive) </p>
  
  <p>Unfortunately, when I try this I get the following result:</p>
  
  <p><img src="https://i.stack.imgur.com/GQ3cu.png" alt="enter image description here"></p>
  
  <p>Two problems can be seen from the above db screen grab:</p>
  
  <pre><code>1. Date for the update send port was inserted into a new activity record 
  2. The record was never completed
  </code></pre>
  
  <p>I was surprised by this because I'd thought since they update port was enlisted to use the same continuation, and the single InterchangeId was being used by all ports for the continuation Id then all the data milestones would be applied to a single activity.</p>
  
  <p>In looking for a solution to this problem I came across the following post on Stack Overflow suggesting that the continuation must be closed from the BAM API: <a href="https://stackoverflow.com/questions/11774416/bam-continuation-issue-with-tpe">BAM Continuation issue with TPE</a>. So, I tried this by calling the following method from an expression shape in my orchestration:</p>
  
  <p>public static void EndBAMContinuation(string continuationId)
          {
              OrchestrationEventStream.EndActivity(CARRIER_ORDER_ACTIVITY_NAME, continuationId);
          }</p>
  
  <p>I can be sure the method was called ok because I wrapped the call with a log entry from the CAT framework which I could see in debug view:</p>
  
  <p><img src="https://i.stack.imgur.com/BIekK.png" alt="enter image description here"></p>
  
  <p>I checked the RcvToOdx{867… continuation Id against the non-closed activity and confirmed they matched:</p>
  
  <p><img src="https://i.stack.imgur.com/Lp2Xk.png" alt="enter image description here"></p>
  
  <p>This would suggest that perhaps the request to end the continuation is being processed before the milestone of the received message from the UpdateAx call?</p>
  
  <p>When I query the Relationsips tables I get the following results:</p>
  
  <p><img src="https://i.stack.imgur.com/AlJDw.png" alt="enter image description here"></p>
  
  <p>Could anyone please advise why the UpdateToAx activity is not being completed?</p>
  
  <p>I realise that I may be able to solve the problem using only the BAM API but I really want to exhaust any possibility of the TPE being fit for purpose first since the TPE is widely used in other BizTalk solutions of the organisation.</p>