'Does IErrorHandler Interface work for a caller or only a called WCF service?
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|