public override void ProcessMessage(SoapMessage message) { StreamWriter writer = null; bool fIsServer = (message.GetType() == typeof(SoapServerMessage)); switch (message.Stage) { case SoapMessageStage.BeforeDeserialize: string resp = new StreamReader(mWireStream).ReadToEnd(); StreamWriter w = new StreamWriter(mApplicationStream); w.WriteLine(resp); w.Flush(); mApplicationStream.Seek(0, SeekOrigin.Begin); break; case SoapMessageStage.AfterSerialize: mApplicationStream.Seek(0, SeekOrigin.Begin); string reqXml = new StreamReader(mApplicationStream).ReadToEnd(); XmlDocument doc = new XmlDocument(); doc.LoadXml(reqXml); Modify(doc); reqXml = doc.InnerXml; mApplicationStream.Seek(0, SeekOrigin.Begin); writer = new StreamWriter(mWireStream); writer.WriteLine(reqXml); writer.Flush(); XmlDocument d = new XmlDocument(); d.LoadXml(reqXml); ServiceManager.RequestSoap = d.LastChild.OuterXml; break; } }
/// <summary> /// Collects the the set of DimeAttachment objects to send in the message. /// For referenced attachments these are collected from the parameter list or return value. /// For unreferenced attachments these are collected from the IDimeAttachmentContainter /// collections. The SOAP envelope and attachments are written into the network stream /// in the AfterSerialize method. /// If an exception has been thrown, the soap message containing the exception is /// not encapsulated. /// </summary> private void BeforeSerialize(SoapMessage message) { if (dimeDir == DimeDir.Response) { return; //because not on request } if (message.Exception == null) { id = message.Action; message.ContentType = DimeContentType; outputAttachments = new ArrayList(); if (message.GetType() != typeof(SoapClientMessage)) { throw new Exception("DIME library not for server side processing"); /* * // check for unreferenced attachments in the container * IDimeAttachmentContainer container = ((SoapServerMessage)message).Server as IDimeAttachmentContainer; * if (container != null) * outputAttachments.AddRange(container.ResponseAttachments); * else * { * // check for referenced attachments in out parameter list * ParameterInfo[] parameters = message.MethodInfo.OutParameters; * for (int i = 0; i < parameters.Length; i++) * { * // Note, using the as operator to test the type since out params have a unique type * object outValue = message.GetOutParameterValue(i); * if ((outValue as DimeAttachment) != null || (outValue as DimeAttachment[]) != null) * AddAttachmentValue(outValue.GetType(), outValue); * } * * // check for referenced attachment in return value * Type returnType = message.MethodInfo.ReturnType; * if (returnType == typeof(DimeAttachment) || returnType == typeof(DimeAttachment[])) * AddAttachmentValue(returnType, message.GetReturnValue()); * } */ } else //client side { // check for unreferenced attachments in the container IDimeAttachmentContainer container = ((SoapClientMessage)message).Client as IDimeAttachmentContainer; if (container != null) { outputAttachments.AddRange(container.RequestAttachments); } else { // check for referenced attachments in the parameter list ParameterInfo[] parameters = message.MethodInfo.InParameters; for (int i = 0; i < parameters.Length; i++) { Type type = parameters[i].ParameterType; if (type == typeof(DimeAttachment) || type == typeof(DimeAttachment[])) { AddAttachmentValue(type, message.GetInParameterValue(i)); } } } } } }
/// <summary> /// Sets the method's DimeAttachment parameters and return value to the stored values. /// </summary> private void AfterDeSerialize(SoapMessage message) { if (contentType == DimeContentType) { if (message.GetType() != typeof(SoapClientMessage)) { throw new Exception("DIME library not for server side processing"); /* * // check for unreferenced attachments in the container * IDimeAttachmentContainer container = ((SoapServerMessage)message).Server as IDimeAttachmentContainer; * if (container != null) * { * if (container.RequestAttachments == null) * throw new InvalidOperationException("The IDimeAttachmentContainer.RequestAttachments property must not be null."); * container.RequestAttachments.AddRange(inputAttachments.Values); * } * else * { * // check for referenced attachments in the parameter list * ParameterInfo[] parameters = message.MethodInfo.InParameters; * for (int i = 0; i < parameters.Length; i++) * { * Type type = parameters[i].ParameterType; * if (type == typeof(DimeAttachment)) * { * // only the id is in the SOAP body so copy over other attachment fields into * // the DimeAttachment object created during deserialization * CopyFieldsFromInputAttachment((DimeAttachment)message.GetInParameterValue(i)); * } * else if (type == typeof(DimeAttachment[])) * { * CopyFieldsFromInputAttachment((DimeAttachment[])message.GetInParameterValue(i)); * } * } * } */ } else //client side { // check for unreferenced attachments in the container IDimeAttachmentContainer container = ((SoapClientMessage)message).Client as IDimeAttachmentContainer; if (container != null) { if (container.ResponseAttachments == null) { throw new InvalidOperationException("The IDimeAttachmentContainer.ResponseAttachments property must not be null."); } container.ResponseAttachments.AddRange(inputAttachments.Values); } else { // check for referenced attachments in the out parameter list ParameterInfo[] parameters = message.MethodInfo.OutParameters; for (int i = 0; i < parameters.Length; i++) { // Note, using the as operator to test the type since out params have a unique type object outValue = message.GetOutParameterValue(i); DimeAttachment a = outValue as DimeAttachment; if (a != null) { CopyFieldsFromInputAttachment(a); } else { DimeAttachment[] aa = outValue as DimeAttachment[]; if (aa != null) { CopyFieldsFromInputAttachment(aa); } } } Type returnType = message.MethodInfo.ReturnType; if (returnType == typeof(DimeAttachment)) { CopyFieldsFromInputAttachment((DimeAttachment)message.GetReturnValue()); } else if (returnType == typeof(DimeAttachment[])) { CopyFieldsFromInputAttachment((DimeAttachment[])message.GetReturnValue()); } } } } }