如何在BizTalk编排中捕获REST服务返回的HTTP 400状态码?
Hey there, let's tackle this BizTalk 2013/R2 CU6 issue you're hitting. Cloning a working send port but still getting suspended messages and routing errors—even with Failed Message Routing enabled and System.Exception catches in your orchestration—can be frustrating, but let's break down the most likely culprits and fixes.
First, let's make sure FMR is set up end-to-end, because it's easy to miss a critical step:
- Send Port Level: You confirmed "Enable Failed Message Routing" is checked, but double-verify it's on the Transport tab of the port properties (not a different tab). For dynamic send ports, this setting might need explicit configuration in your orchestration code, not just the binding.
- Orchestration Send Shape: This is the most overlooked detail! Right-click the send shape in your orchestration, open its properties, and ensure Route Failed Messages is checked. If this is off, even with FMR enabled on the send port, BizTalk won't route the failed message out of the orchestration—it'll just suspend it.
Using System.Exception is broad, but BizTalk has specific exception types that might slip through, or your catch block might not properly handle the failed message:
- Catch Specific Exceptions: Add catches for
Microsoft.XLANGs.BaseTypes.XLANGException(the base exception for BizTalk orchestration errors) and transport-specific exceptions (likeSystem.Net.WebExceptionfor WCF/HTTP ports) alongsideSystem.Exception. This helps narrow down if the error stems from orchestration logic or the transport layer. - Publish the Failed Message: Catching the exception isn't enough—you need to ensure the failed message gets published to the MessageBox so FMR can route it. In your catch block, use the
Publishmethod to send the failed message out, or add a send shape pointing to a dedicated failed message port. If you don't publish it, the message stays trapped in the orchestration, leading to a suspended instance.
You modified the send port's name and operation binding—let's confirm those changes didn't break compatibility:
- Operation Binding Exact Match: BizTalk is extremely picky about contract names, operation names, and namespaces. Double-check that the operation you bound to matches the target service's exact contract (case-sensitive!). Even a tiny typo here can cause routing failures because the message type won't align with the send port's subscription.
- Hidden Configuration Details: Did you copy all original send port settings? Easy-to-miss items include custom pipelines, filters, transport credentials (usernames, certificates), timeout values, or proxy settings. Compare the original port and your cloned port side-by-side in the BizTalk Admin Console to spot discrepancies.
- Validate Subscriptions: Go to your cloned send port's properties, open the Subscriptions tab, and verify the subscription criteria. Ensure it matches the messages your orchestration is publishing. If the subscription is missing a key property (like message type or a custom context property), BizTalk won't route the message to the port, causing an unrecoverable routing error.
Before guessing, get concrete info from BizTalk's logs:
- Suspended Message Details: In the BizTalk Admin Console, find the suspended send port message, right-click it, and select View Error Information. Copy the full error message and code—this will tell you if it's a transport error (e.g., "Could not connect to endpoint"), message validation error, or subscription mismatch.
- Track Orchestration Events: Enable tracking on your orchestration (right-click the orchestration in the Admin Console, select Tracking) and check all relevant tracking options. Run a test, then review tracked events in the Group Hub—this shows exactly where the orchestration fails and what context properties are set on the message.
To rule out orchestration complexity, build a simple test:
- Create a basic orchestration that only receives a test message and sends it to your cloned send port. No extra logic, no complex exception handling—just a straight send.
- If this test works, the issue lies in your original orchestration's logic (e.g., overwritten context properties, missing pre-send steps). If it fails, the problem is definitely with the cloned send port's configuration.
These steps should help you pinpoint the issue. Start with the send shape's Route Failed Messages setting—it's the most common gotcha. Then dig into the error details, because BizTalk almost always tells you exactly what's wrong if you look closely.
内容的提问来源于stack exchange,提问作者NealWalters

