Thank you Giba!

Yes I have now gone back and changed the call from the Business Service to act synchronously and this has rectified the issue!  The simplest way to do this was to set the Ack Mode to 'application' so that a new message was not received on the Service until the process had sent back an application Ack for the previous message (which it does at the end of the process).

Many thanks for all of your help solving this!

Thanks Julian,

I have posed the traces of both messages below.  The process makes several calls to the operation.  As you ca see by the timings in the trace window, Message 2 is in the process making calls during the time that Message 1 is still in the process?  Could the BPL be starting to process Message 2 inbetween processing Message 1? (whilst waiting for Call Responses for Message 1?)

Message 1:

Message 2:

Thanks Rubens/Sean/Dmitry,

I decided to switch to the long strings route as the documents are small.  I couldn't get this working either but it was because I wasn't reading the stream in a number divisible by 3 (I was just doing a .ReadLine() ).  Have performed a Read(12000) and it now works a treat!  PDF opening up in the supplier's system.

do context.streamPDF.Rewind()
while 'context.streamPDF.AtEnd
{
  set line=context.streamPDF.Read(12000)
  set context.strDocument =context.strDocument_line
}
set context.strDocumentEncoded = $system.Encryption.Base64Encode(context.strDocument)

Have worked it out myself, read in PDF file as %FileBinaryStream and then read through and count the occurrences of /Page (but not /Pages), and this seems to be giving me the correct number of pages for all of the files I have tried so far!

Method OnProcessInput(pInput As %FileBinaryStream, pOutput As %RegisteredObject) As %Status
{
set tsc=$$$OK
Do pInput.Rewind()
set pagecount  = 0
While 'pInput.AtEnd 
{
//set line=pInput.Read(200)
set line=pInput.ReadLine()
if ($FIND(line,"/Type/Page")
{
if '$FIND(line,"/Pages")
{
set pagecount = pagecount + 1
}
}
}
$$$TRACE(pagecount)
Quit tsc
}

We don't get a lot of choice/option in how we move documents and always seem to be dictated to by the source and receiving systems. We use Ensemble to pick up/receive documents and then manipulate them into whatever method the receiving system can receive them in. Some examples of what we do; * We pick up documents as streams from within an application database (using SQL Adapter), and querying other application database tables for metadata. * We then transform this into an MDM^T02 message and send out (with PDF stream or HTML inside). * We may also use Ensemble to send an email with the document attached (from and to secure email addresses). * One system we have to interact with using their API which means creating an XML request (again with the document stream contained within the XML payload). * Mostly an application will drop the document along with an accompanying xml metadata file into a folder which Ensemble will then need to process. Up until this point we have never been able to specify to any system suppliers how we want them to send/receive documents, however now as we are doing more and more document sending then we will try to specify 'document moving preferences' during the tendering stage with suppliers.