1

Referring to this interface: https://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.ierrorhandler(v=vs.110).aspx

I have coded class that implements IErrorHandler, and it's not firing (although using debugger I see methods like Validate, AddBindingParameters, ApplyClientBehavior, but didn't see ApplyDispatchBehavior run.

The example I used to write it was a BizTalk orchestration published as a webservice (https://blog.tallan.com/2014/09/29/wcf-webhttp-and-custom-json-error-messages/comment-page-1/#comment-232591); but in my case, I'm a BizTalk orchestration calling an external webservice (I am the client, not the server). I want to trap and change the 400 status.

So in his code sample, he adds the ErrorHandler to endpointDispatcher.ChannelDispatcher in the ApplyDispatcherBehavior. After doing some reading, looks like ApplyDispatchBehavior is only when you are the server. Can I add the error behavior "to dispatch" in the ApplyClientBehavior?

public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
    clientRuntime.MessageInspectors.Add(new BizTalkRESTTransmitHandler());
    #can IErrorHandler be added to client? 
}

// Apparently ApplyDispatchBehavior only applies if you are the server, not the client 
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
    BizTalkRESTTransmitErrorHandler handler = new BizTalkRESTTransmitErrorHandler();
    endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add(handler); 
}

I'm hoping that someone WCF pro vs a BizTalk person can actually answer. BizTalk has a WCF adapter (acting as the WCF client in this case), and we have ways to implement custom behaviors within that structure. I was also using the AfterReceiveReply method; but I think BizTalk stopped the adapter before it could run that method. I was hoping IErrorHandler might allow me to do the intercept.

I have logic for AfterReceiveReply; but it's not running (although BeforeSendRequest is). I think the BizTalk Adapter is calling the message because of the bad HTTP status and not letting me inspect it.

My related post written in BizTalk terminology: How to prevent BizTalk 2013/R2 WCF-WebHttp Rest SendPort from Suspending on Http Status=400

NealWalters
  • 17,197
  • 42
  • 141
  • 251
  • 1
    `IErrorHandler` is server-side only (a string indication is the location in the `System.ServiceModel.Dispatcher` namespace which is for server side stuff). Its primary reason is to provide a custom fault-message for a serverside occurring exception. Others have similar [questions](https://stackoverflow.com/questions/33734660/wcf-client-side-error-handling) which might be helpful. – Christian.K Apr 07 '18 at 16:37
  • I'm working within the BizTalk Server framework; and the only thing I think I can add is a CustomBehavior. I want to change the 400 error to a 200 error before BizTalk sees it, so my program in BizTalk can handle the JSON in the message. 400 is treated as sever SendPort error and doesn't clean-up nicely. – NealWalters Apr 09 '18 at 14:16
  • 1
    I've tried IClientMessageInspector but tusing the debugger, I see that AfterReceiveReply isn't being called when there is the 400 error. – NealWalters Apr 09 '18 at 14:24

0 Answers0