I have faced the issue of calling web service from BizTalk, where intermittently either service is not available or there is some problem in connecting the service. Service can return response error code which is other than HTTP 200 code ie. HTTP 400 or HTTP 500 code. BizTalk doesnt like it. Send port will treat as warning, write warning in event viewer and retries. But eventually if problem and error persists then error will be thrown from send port. This error will be received in Orchestration.
You can set exception handler block to catch the exception i.e. System.Exception or System.EntryPointNotFoundException. You can handle the exception gracefully. But send port instance will get suspended. This will not go away unless manually terminated. Since the exception is thrown from send port and probably it is valid response, there is no point in resuming it too. If you try doing it, orchestration which had called the service has already handled exited since exception has been handled in exception handler block.
This scenario needs to be handled by a separate orchestration which we can call "SendPortExceptionHandler". This orchestration will have only one receive shape connected to receive port. It will receive message of type Raw Xml. A filter needs to be created like below:
ErrorReport.FailureCode Exists And ErrorReport.MessageType == schema_namespace#root_node |
You can add multiple filters, so that all exceptions at send port will be handled by single orchestration.
-----------------------------------------------------------------------------------------------------------------------------
If we get exception say System.EntryPointNotFoundException and we want to handle this manually. We might get this error if end point is not available or network is down. Then we might want to suspend the orchestration and retry manually. For doing this, we need to add a loop. Add a scope in that loop. Catch the specific exception in that scope exception handler. Please see below:
In the first expression box we will initialize values for retry.
// Set retry to true
ServiceRetry = true;
ServiceRetryCount = 0;
In the internal scope (Mule ESB Scope) I am catching System.EntryPointNotFoundException. You can add another exception handler block to throw other errors. In this block I am setting values as below:
// Set retry to true
ServiceRetry = true;
ServiceRetryCount = ServiceRetryCount + 1;
In decide shape I am checking if retry count ServiceRetryCount <= 3 then it suspends the flow else exception will thrown. It will create a finite number of retries and orchestration will exit gracefully.
In outer all other exceptions are caught and thrown back to the calling orchestration.
This way, we can handle service end point related and web exceptions in BizTalk.