Error: “Safe handle has been closed” when receiving a response message on a SOAP port.

One of the customers was working on BizTalk Server 2010. The BizTalk databases were hosted on SQL Server 2008 R2. He was getting the below error when he gets a response to a SOAP adapter for one of his applications:

Error:
"A response message sent to adapter "SOAP" on receive port "ReceiveCreateUserProfile" with URI
"/xxxxxx.BizTalk.CreateUserProfile/xxxxxx_BizTalk_CreateUserProfile_CreatePOUserProfile_CreateUserProfile_WebServicePort.asmx" is suspended.

Error details: Safe handle has been closed

1. The issue was with the BackupBizTalkServer job not being configured and enabled. Followed
the mentioned below steps.

   a. Collected the MessageBoxViewer report
   b. It showed database throttling
   c. The jobs MessageBox_Message_ManageRefCountLog_BizTalkMsgBoxDb and BackupBizTalkServer were disabled
   d. Configured the job BackupBizTalkServer and enabled it (Refer https://msdn.microsoft.com/en-us/library/aa546765.aspx)
e
. Enabled the job MessageBox_Message_ManageRefCountLog_BizTalkMsgBoxDb
f. Collected a fresh MessageBoxViewer report and it did not show database throttling this time 

2. In another case there were issues with the DTAPurgeAndArchive job where the tracking spool table was very heavy. In this case, follow the mentioned below steps.

   a. Collected the MessageBoxViewer report
   b. Tracking spool table had hug number of rows.
   c. Reduced the number of ‘Harddays’ the data is kept in the database for the DTAPurgeAndArchive job.
   d. Once you clear the DTADB dta_DebugTrace and dta_MessageInOutEvents tables, the spool table will catch up and so will the SOAP adapter.
   e. Terminated all the suspended instances from the BizTalk MMC.

Note:
a. Increase the frequency of the Purge and Archiving job if required
   b. Terminator tool can also be used to get rid of the suspended instances, caching instances, DTA Orphaned instances and the DTA mark log rows.
       You can download the terminator tool from https://www.microsoft.com/download/en/details.aspx?id=2846
       BizTalk terminator download and install information available at : https://blogs.msdn.com/b/biztalkcpr/archive/2009/09/30/biztalk-terminator-download-install-info.aspx
       Using BizTalk Terminator to resolve issues identified by BizTalk MsgBoxViewer and the BizTalk 2010 Monitor BizTalk Server Job : https://blogs.msdn.com/b/biztalkcpr/archive/2011/02/10/using-biztalk-terminator-to-resolve-issues-identified-by-biztalk-msgboxviewer.aspx

Configure "Max Degree of Parallelism for MsgBoxDB Servers" to ‘1’ as required by BizTalk (Refer https://support.microsoft.com/kb/899000) if it is not already set to 1

Note : The SOAP adapter is deprecated in BizTalk Server 2010. You should use the WCF-BasicHttp to communicate with Web services and clients that conform to the WS-I Basic Profile 1.1. To communicate with Web services and clients that conform to WS-*, use the WCF-WSHttp adapter.
Refer https://msdn.microsoft.com/en-us/library/aa559720.aspx .

Written by:
Kshitij Dattani

Reviewed by:
Jainath Ramanathan

Microsoft GTSC India