none
Create a message from XML By overriding BeforeSendRequest method in a class that implemets IClientMessageInspector interface RRS feed

  • Question

  • Hi,

    I am trying to override the  BeforeSendRequest  to send  a message. I need to POST the following XML to https://www.intacct.com/ia/xml/xmlgw.phtml address.  But i am getting "System.ArgumentNullException: Value cannot be null." error in the send port.

    <?xml version="1.0" encoding="UTF-8"?>
    <request>
        <control>    
            <senderid>intacct_dev</senderid>
            <password>babbage</password>
            <controlid>XML Sample</controlid>
        </control>
        <operation>
            <authentication>
                <login>
                    <userid>xmluser</userid>
                    <companyid>XML Sample</companyid>
                    <password>abc123</password>
                </login>
            </authentication>
            <content>            
                <function controlid="f1">
                    <create_gltransaction>
                        <journal>GJ</journal>                    
                    </create_gltransaction>
                </function>
            </content>
        </operation>
    </request>

                 
    public object BeforeSendRequest(ref Message request, IClientChannel channel)
            {

    var requestBody = XElement.Load(request.GetReaderAtBodyContents());


                var bodyElement = requestBody.Element(Body);
                var requestMessageProperty = new HttpRequestMessageProperty
                {
                    Method = "POST",
                    SuppressEntityBody = bodyElement == null
                };
                foreach (var header in requestBody.Elements(Header))
                {
                    requestMessageProperty.Headers.Add(
                        header.Attribute("name").Value,
                        header.Value);
                }

                request = Message.CreateMessage(request.Version, request.Headers.Action, bodyElement.ToString());

                request.Properties[HttpRequestMessageProperty.Name] = requestMessageProperty;
    return request ;
    }

    Please help me in overriding the method.

    Thanks,

    Sanjib



    sanjib medhi

    Wednesday, May 16, 2012 6:03 AM

Answers