Extracting detail from a WCF FaultException response

前端 未结 4 2470
慢半拍i
慢半拍i 2021-02-19 22:29

I am successfully working with a third party soap service. I have added a service reference to a soap web service which has auto generated the classes.

When an error oc

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 23:25

       public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
    
            if (reply.IsFault)
            {
                // Create a copy of the original reply to allow default WCF processing
                MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
                Message copy = buffer.CreateMessage();  // Create a copy to work with
                reply = buffer.CreateMessage();         // Restore the original message 
    
                MessageFault faultex = MessageFault.CreateFault(copy, Int32.MaxValue); //Get Fault from Message
                FaultCode codigo = faultex.Code;
                //if (faultex.HasDetail)... //More details
    
                buffer.Close(); 
    

提交回复
热议问题