Exemplo n.º 1
0
        /// <summary>
        /// Reads method invocation result.
        /// </summary>
        /// <param name="stream">Stream.</param>
        /// <param name="marsh">Marshaller.</param>
        /// <param name="keepPortable">Portable flag.</param>
        /// <returns>
        /// Method invocation result, or exception in case of error.
        /// </returns>
        public static object ReadInvocationResult(IPortableStream stream, PortableMarshaller marsh, bool keepPortable)
        {
            Debug.Assert(stream != null);
            Debug.Assert(marsh != null);

            var mode = keepPortable ? PortableMode.ForcePortable : PortableMode.Deserialize;

            var reader = marsh.StartUnmarshal(stream, mode);

            object err;

            var res = PortableUtils.ReadInvocationResult(reader, out err);

            if (err == null)
            {
                return(res);
            }

            var portErr = err as IPortableObject;

            throw portErr != null
                ? new ServiceInvocationException("Proxy method invocation failed with a portable error. " +
                                                 "Examine PortableCause for details.", portErr)
                : new ServiceInvocationException("Proxy method invocation failed with an exception. " +
                                                 "Examine InnerException for details.", (Exception)err);
        }