none
SOAP Action Override the Actual "Send" of a Soap Message (How to Prevent Default Behavior When Sending) RRS feed

  • Question

  • Hello,

    I have an inspector that already sends the SOAP message using an HTTP Post instead:

    public class SoapInspectorBehavior : IEndpointBehavior
        {
            public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
            {
            }
            public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
            {
                clientRuntime.ClientMessageInspectors.Add(new SoapInspectorBehavior());
            }
            public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
            {
             
            }
            public void Validate(ServiceEndpoint endpoint)
            {
            }
        }


    And the actual `SOAPEndpointBehavior`:

     public class SOAPInspector : IClientMessageInspector
        {
            public static HttpClient client = new HttpClient();
    
            private bool isFirstTime = true;
    
           public void AfterReceiveReply(ref Message reply, object correlationState)
            {
    
            }
    
     public object BeforeSendRequest(ref Message request, IClientChannel channel)
            {
     InspectorPayload inspectorPayload = new InspectorPayload();
    
    HttpRequestMessage(HttpMethod.Post, new Uri("http://10.0.0.155:3010"));
    
                    XDocument xRequest = XDocument.Parse(request.ToString());
    
                    client.DefaultRequestHeaders
                     .Accept
                     .Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
    httpRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(inspectorPayload), Encoding.UTF8, "application/json");
    
    
                    var body = httpRequestMessage.Content.ReadAsStringAsync().Result;
            }
    
        }

    Is there any way to stop the original message from being sent after executing the custom inspector?


    • Edited by A_Failure Friday, September 20, 2019 2:17 PM Formatting of first code sample
    Friday, September 20, 2019 2:16 PM

Answers

  • Hi,

    Sorry, I haven’t got your thought. I haven't heard of the implementation of similar requirement, which seems impossible to me. 
    Besides, the message inspector is located at the entrance and exit of the communication channel and can check the format and content of the message. From this point of view, we can simply in the bottom of the BeforeSendRequest method close the channel or empty the request, could those are solutions to your problem? 
    Best Regards
    Abraham

    • Marked as answer by A_Failure Friday, December 20, 2019 2:12 AM
    Monday, September 23, 2019 8:52 AM
    Moderator

All replies

  • Hi,

    Sorry, I haven’t got your thought. I haven't heard of the implementation of similar requirement, which seems impossible to me. 
    Besides, the message inspector is located at the entrance and exit of the communication channel and can check the format and content of the message. From this point of view, we can simply in the bottom of the BeforeSendRequest method close the channel or empty the request, could those are solutions to your problem? 
    Best Regards
    Abraham

    • Marked as answer by A_Failure Friday, December 20, 2019 2:12 AM
    Monday, September 23, 2019 8:52 AM
    Moderator
  • That's exactly what ended up working. Thank you!
    Friday, December 20, 2019 2:13 AM