예제 #1
0
        private static Boolean IsBuiltInErrorResponse <T>(IServiceResponse <T> originalResponse)
        {
#if NET45_OR_GREATER
            var typeInfo = originalResponse.GetType().GetTypeInfo();
            return((originalResponse is ErrorResponse <T>) ||
                   (typeInfo.IsGenericType && typeof(ErrorResponse <>).GetTypeInfo().IsAssignableFrom(typeInfo.GetGenericTypeDefinition().GetTypeInfo())));
#else
            var typeInfo = originalResponse.GetType();
            return((originalResponse is ErrorResponse <T>) ||
                   (typeInfo.IsGenericType && typeof(ErrorResponse <>).IsAssignableFrom(typeInfo.GetGenericTypeDefinition())));
#endif
        }
예제 #2
0
        private Stream EndProcessRequest(IAsyncResult result)
        {
            MemoryStream ostrm = new MemoryStream();

            try {
                if (m_callback != null)
                {
                    IServiceResponse response = m_callback.EndProcessRequest(result);

                    string contentType = WebOperationContext.Current.IncomingRequest.ContentType;

                    if (contentType == "application/octet-stream")
                    {
                        BinaryEncoder encoder = new BinaryEncoder(ostrm, this.m_quotas.MessageContext);
                        encoder.EncodeMessage(response);
                    }
                    else
                    {
                        HttpsTransportChannel.WriteSoapMessage(
                            ostrm,
                            response.GetType().Name,
                            response,
                            this.m_quotas.MessageContext);
                    }

                    ostrm.Position = 0;
                }
            } catch (Exception e) {
                Utils.Trace(e, "TCPLISTENER - Unexpected error sending result.");
            }

            return(ostrm);
        }
예제 #3
0
        private static Boolean IsBuiltInErrorResponse <T>(this IServiceResponse <T> originalResponse)
        {
            var typeInfo = originalResponse.GetType().GetTypeInfo();

            return(originalResponse is ErrorResponse <T> ||
                   (typeInfo.IsGenericType && typeof(ErrorResponse <>)
                    .GetTypeInfo()
                    .IsAssignableFrom(typeInfo.GetGenericTypeDefinition().GetTypeInfo())));
        }
예제 #4
0
        internal static IServiceResponse <T2> CreateGenericErrorResponse <T, T2>(IServiceResponse <T> originalResponse, Error error)
        {
            if (IsBuiltInErrorResponse(originalResponse))
            {
                return(new ErrorResponse <T2>(error));
            }

            try
            {
                return(Activator.CreateInstance(
                           originalResponse.GetType()
                           .GetGenericTypeDefinition()
                           .MakeGenericType(typeof(T2)),
                           error) as IServiceResponse <T2>);
            }
            catch (TargetInvocationException)
            {
                // No supportable constructor found! Return default.
                return(new ErrorResponse <T2>(error));
            }
        }
예제 #5
0
        internal static IServiceResponse <T> CreateGenericDataResponse <T>(IServiceResponse <T> originalResponse, T data)
        {
            if (IsBuiltInDataResponse(originalResponse))
            {
                return(new DataResponse <T>(data));
            }

            try
            {
                return(Activator.CreateInstance(
                           originalResponse.GetType()
                           .GetGenericTypeDefinition()
                           .MakeGenericType(typeof(T)),
                           data) as IServiceResponse <T>);
            }
            catch (TargetInvocationException)
            {
                // No supportable constructor found! Return default.
                return(new DataResponse <T>(data));
            }
        }