none
Get DataContract DataMember Value from WCF Channel Message RRS feed

  • Question

  •    how to get the SOAP request value of datamember of datacontract  from WCF at AfterReceiveRequest method

        SOAP Request is


        <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
        <s:Header>
        <a:Action s:mustUnderstand="1">http://tempuri.org/ITcpService/GetData</a:Action>
        <a:MessageID>urn:uuid:fa410c1f-4b74-42e5-998d-565cd5c7b092</a:MessageID>
        <a:ReplyTo>
        <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
        </a:ReplyTo>
        <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPoyXtX3m/PSJBo+4Vd2taPwgAAAAAB+2JFplBDU6oJYlfkZ/um28yri7PLBZFmtLNf3F75EMACQAA</VsDebuggerCausalityData>
        <a:To s:mustUnderstand="1">net.tcp://localhost/mytcpservice/TcpService.svc</a:To>
        </s:Header>
        <s:Body>
        <GetData xmlns="http://tempuri.org/">
        <value xmlns:b="http://schemas.datacontract.org/2004/07/mytcpservice.requests" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <b:Token>0</b:Token>
        <b:Data>7</b:Data>
        <b:Data2>0</b:Data2>
        </value>
        </GetData>
         </s:Body>
         </s:Envelope>

        public class TestActivation : IDispatchMessageInspector
        {
        public object AfterReceiveRequest(ref Message request, IClientChannel     channel, InstanceContext instanceContext)
        {
        //here fetch Token value if exists
        }
        }
        

    fetch Token value by generic

    Tuesday, January 27, 2015 11:52 AM

Answers

  • Hi,

    At the server side, implementations of IDispatchMessageInspector get a chance to inspect the incoming message right after the request is received via the AfterReceiveRequest method. Besides the message, the method is also passed the channel through which the message arrived (which contains information about any current sessions, local and remote address, and so on), and the instance context associated with the service (with references to the host, and any extensions associated with it).

    One thing that deserves mention is that the Message object to both methods is passed by reference. WCF Message objects can only be “consumed” once – and “consumed” can mean read, written or copied. The message body is essentially a read-once stream, so once it’s consumed it cannot be used again. So if, in the inspector code, one were to read the message, the WCF runtime wouldn’t be able to reuse that message in the rest of its pipeline (i.e., to encode it to send as a reply or to parse it into operation parameters). So if the inspector code needs to read the message, it’s the responsibility of the inspector to recreate the message.

    For more information, you could refer to:

    http://blogs.msdn.com/b/carlosfigueira/archive/2011/04/19/wcf-extensibility-message-inspectors.aspx

    http://trycatch.me/adding-custom-message-headers-to-a-wcf-service-using-inspectors-behaviors/

    http://www.primaryobjects.com/CMS/Article121

    Regards

    Wednesday, January 28, 2015 7:18 AM
    Moderator