0
votes

I'm using BizTalk Server 2020 One-way Receive Ports and One-way Send Ports with WCF-WebHttp adapters to handle asynchronous REST communication. I don't need to make any payload transformations, that's why for performance reasons I'm not using orchestrations.

I need to handle Error HTTP status codes that for some codes (e.g. 500) message will be suspended and for some (e.g. 400) it will be deleted.

BizTalk throws System.Net.WebException when a REST call returns an HTTP status code other than 2XX. Error code can only be read from its message. Also when exception is thrown code in Send Port behaviors and pipelines isn't invoked.

System.Net.WebException: The remote server returned an unexpected response: (400) Bad Request.

I know how to make Send Ports that listen for messages with ErrorType == FailedMessage and delete them, but I don't know how to create filter which only affects messages with certain HTTP status codes.

Is there any way to do it without orchestration?

1

1 Answers

1
votes

There are two issue in BizTalk which I've written about on my blog which I've included below, and it also links to other blogs that have some workarounds. To sum that up, it is to use the BRE Pipeline Framework component to inspect to see if it is a good response or a bad one, and to have a custom endpoint behaviour that sanitises the fault.

BUG: BIZTALK WCF-WEBHTTP ADAPTER DOES NOT SET THE MESSAGE TYPE ON ERROR Details: When you get a non 200 series http status code from a RESTful service using the WCF-WebHttp adapter, the SOAP fault message published to the message box does not have the context property MessageType. This means you cannot map it or catch it in a Fault on the Logical Port in the Orchestration Work around: Catch it in a System.Exception block in the Orchestration, see (BizTalk 2013 R2 JSON Encoder error – “Object reference not set to an instance of an object” – Part 1) or use BRE rules in a Pipeline to handle the SOAP Exception see BizTalk 2013 R2 JSON Encoder error – “Object reference not set to an instance of an object” – Part 2

BUG: BIZTALK WCF-WEBHTTP ADAPTER DOES NOT SET HTTP STATUS CODE ON ERROR Details: When you consume a RESTful service and get a non 200 series status code back, it will throw a SOAP exception in the Adapter and not promote the http status code in the message context InboundHttpStatusCode or InboundHttpStatusDescription like it does for a successful ones. If these were in the Context Properties it would make handling exceptions easier. InboundHttp Work around: Have to inspect the text in the System.Exception message to work out what exception was thrown