none
Removing the node/elment in message inspector RRS feed

  • Question

  • Hi,

    We have created custom wcf behavior and this behavior check the size of attachement node present in the message and if it is more than 2.5 then we need to replace the attachement content with small dummy text(e.g. attachment has been removed due to large size) and then pass it to the next level.

    1) check the attachement size:

    long size=AttachmentReader.ReadElementContentAsString().Length

    here attachmentreader is xmlreader.

    2)calling the removeattachment function to remove the attachment content:

    using (XmlTextWriter wr = new XmlTextWriter(sr))
                {
                    wr.Formatting = Formatting.Indented;
                    while (bodyReader.Read())
                    {
                        switch (bodyReader.NodeType) //Swith to respective case if bodyreader is startelement, Endelement, value etc..
                        {
                            case XmlNodeType.Element:

                                if (bodyReader.Name.Equals(AtmtRecord)) // if Element is "Attachment Record" then read attachment Name 
                                {
                                    
                                    HasAtbt = bodyReader.HasAttributes; // check if record has any attributes
                                    Ns = bodyReader.NamespaceURI;// This will write any value within xmlns
                                    count = count + 1;
                                    bodyReader.MoveToNextAttribute();
                                    bodyReader.ReadToFollowing(AtmtName);//"attachment_content_name"
                                   
                                    FileName = FileName.Trim() + bodyReader.ReadElementContentAsString() + ",";
                                    Msg = AtmtMsg + ":" + FileName.Trim();
                                    Msg = EncodeContentMsgToBase64(Msg);// enode the above string message to base64 as SN decodes any message from attachment content node
                                    bodyReader.MoveToNextAttribute();
                                 
                                    if (count == countAttachment) // Finally write the attachment node with configured message (converted to base64) this will read all the attachment nodes and writes only one record inspite of multiple attachments
                                    {
                                        if (HasAtbt) // if "attachments" record has any attributes then create attachments record with along attributes
                                        {
                                            wr.WriteStartElement(AtmtRecord, Ns);//This will create "attachments" record with attribute
                                            wr.WriteElementString(AtmtName,"ESBRemovedAttachment.txt");//"attachment_content_name"
                                            wr.WriteElementString(AtmtType,"text/plain");//"attachment_content_type"
                                            wr.WriteElementString(AtmtNode,Msg);//attachme content node
                                            wr.WriteEndElement();

                                        }
                                        else // if there are no attributes for a node then create record without adding any attributes for the nodes
                                        {
                                            wr.WriteStartElement(AtmtRecord);//This will create "attachments" record without attribute
                                            wr.WriteElementString(AtmtName, "ESBRemovedAttachment.txt");//"attachment_content_name"
                                            wr.WriteElementString(AtmtType, "text/plain");//"attachment_content_type"
                                            wr.WriteElementString(AtmtNode, Msg);//attachme content node
                                            wr.WriteEndElement();
                                        }

                                       
                                     }

    ......

    ......

    here we are again creating the message structure using xmlwriter without actual attachement content.

    This is working fine in case of low volume of message or message size is less. when we increase the message size to 3 MB and trigger 10 such messages at one time , it starting throwing error/warning .

    Is there any other way to remove the attachment content or remove that node itself and pass the remaining message 


    Manish

    Tuesday, August 12, 2014 7:00 AM

All replies

  • Hi,

    please post your error message for us.

    and have you checked that  the message size has exceeded the message max size which wcf support

    Wednesday, August 13, 2014 6:18 AM