Exemplo n.º 1
0
        /// <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));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <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());
                        }
                    }
                }
            }
        }