private void SerializeResponse(IServerChannelSinkStack sinkStack, IMethodReturnMessage methodReturn, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            // get response stream
            responseHeaders = new TransportHeaders();
            responseStream  = sinkStack.GetResponseStream(methodReturn, responseHeaders);
            if (responseStream == null)
            {
                responseStream = new ChunkedMemoryStream();
            }

            // serialize response
            _formatter.SerializeResponse(methodReturn, responseHeaders, responseStream);
        }
Exemple #2
0
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack,
                                               IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream,
                                               out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            sinkStack.Push(this, null);
            ServerProcessing res;

            try
            {
                string url = (string)requestHeaders["__RequestUri"];
                string uri;
                receiver.Parse(url, out uri);
                if (uri == null)
                {
                    uri = url;
                }

                MethodCallHeaderHandler mhh = new MethodCallHeaderHandler(uri);
                requestMsg = (IMessage)_binaryCore.Deserializer.Deserialize(requestStream, new HeaderHandler(mhh.HandleHeaders));

                res = next_sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream);
            }
            catch (Exception ex)
            {
                responseMsg     = new ReturnMessage(ex, (IMethodCallMessage)requestMsg);
                res             = ServerProcessing.Complete;
                responseHeaders = null;
                responseStream  = null;
            }

            if (res == ServerProcessing.Complete)
            {
                for (int n = 0; n < 3; n++)
                {
                    responseStream  = null;
                    responseHeaders = new TransportHeaders();

                    if (sinkStack != null)
                    {
                        responseStream = sinkStack.GetResponseStream(responseMsg, responseHeaders);
                    }
                    if (responseStream == null)
                    {
                        responseStream = new MemoryStream();
                    }

                    try {
                        _binaryCore.Serializer.Serialize(responseStream, responseMsg);
                        break;
                    } catch (Exception ex) {
                        if (n == 2)
                        {
                            throw ex;
                        }
                        else
                        {
                            responseMsg = new ReturnMessage(ex, (IMethodCallMessage)requestMsg);
                        }
                    }
                }

                if (responseStream is MemoryStream)
                {
                    responseStream.Position = 0;
                }


                sinkStack.Pop(this);
            }
            return(res);
        }
Exemple #3
0
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack,
                                               IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream,
                                               out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            // Check whether the request was already processed by another
            // formatter sink and pass the request to the next sink if so.
            if (requestMsg != null)
            {
                return(next_sink.ProcessMessage(sinkStack,
                                                requestMsg,
                                                requestHeaders,
                                                requestStream,
                                                out responseMsg,
                                                out responseHeaders,
                                                out responseStream));
            }

            // Check whether the request is suitable for this formatter
            // and pass the request to the next sink if not.
            // Note that a null content-type is handled as suitable,
            // otherwise no other sink will be able to handle the request.
            string contentType = requestHeaders["Content-Type"] as string;

            if (contentType != null && contentType != "application/octet-stream")
            {
                try {
                    return(next_sink.ProcessMessage(sinkStack,
                                                    requestMsg,
                                                    requestHeaders,
                                                    requestStream,
                                                    out responseMsg,
                                                    out responseHeaders,
                                                    out responseStream));
                } catch {
                    // Let this formatter handle the exception.
                }
            }

            sinkStack.Push(this, null);
            ServerProcessing res;

            try
            {
                string url = (string)requestHeaders[CommonTransportKeys.RequestUri];
                string uri;
                receiver.Parse(url, out uri);
                if (uri == null)
                {
                    uri = url;
                }

                MethodCallHeaderHandler mhh = new MethodCallHeaderHandler(uri);
                requestMsg = (IMessage)_binaryCore.Deserializer.Deserialize(requestStream, new HeaderHandler(mhh.HandleHeaders));

                res = next_sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream);
            }
            catch (Exception ex)
            {
                responseMsg     = new ReturnMessage(ex, (IMethodCallMessage)requestMsg);
                res             = ServerProcessing.Complete;
                responseHeaders = null;
                responseStream  = null;
            }

            if (res == ServerProcessing.Complete)
            {
                for (int n = 0; n < 3; n++)
                {
                    responseStream  = null;
                    responseHeaders = new TransportHeaders();

                    if (sinkStack != null)
                    {
                        responseStream = sinkStack.GetResponseStream(responseMsg, responseHeaders);
                    }
                    if (responseStream == null)
                    {
                        responseStream = new MemoryStream();
                    }

                    try {
                        _binaryCore.Serializer.Serialize(responseStream, responseMsg);
                        break;
                    } catch (Exception ex) {
                        if (n == 2)
                        {
                            throw ex;
                        }
                        else
                        {
                            responseMsg = new ReturnMessage(ex, (IMethodCallMessage)requestMsg);
                        }
                    }
                }

                if (responseStream is MemoryStream)
                {
                    responseStream.Position = 0;
                }


                sinkStack.Pop(this);
            }
            return(res);
        }
        private void SerializeResponse(IServerChannelSinkStack sinkStack, IMethodReturnMessage methodReturn, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            // get response stream
            responseHeaders = new TransportHeaders();
            responseStream = sinkStack.GetResponseStream(methodReturn, responseHeaders) ?? new ChunkedMemoryStream();

            // serialize response
            _formatter.SerializeResponse(methodReturn, responseHeaders, responseStream);
        }
		public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
							IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream,
							out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
		{
			// Check whether the request was already processed by another
			// formatter sink and pass the request to the next sink if so.
			if (requestMsg != null)
				return next_sink.ProcessMessage (sinkStack,
								 requestMsg,
								 requestHeaders,
								 requestStream,
								 out responseMsg,
								 out responseHeaders,
								 out responseStream);

			// Check whether the request is suitable for this formatter
			// and pass the request to the next sink if not.
			// Note that a null content-type is handled as suitable,
			// otherwise no other sink will be able to handle the request.
			string contentType = requestHeaders["Content-Type"] as string;
			if (contentType != null && contentType != "application/octet-stream") {
				try {
					return next_sink.ProcessMessage (sinkStack,
						requestMsg,
						requestHeaders,
						requestStream,
						out responseMsg,
						out responseHeaders,
						out responseStream);
				} catch {
					// Let this formatter handle the exception.
				}
			}

			sinkStack.Push (this, null);
			ServerProcessing res;

			try
			{
				string url = (string)requestHeaders[CommonTransportKeys.RequestUri];
				string uri;
				receiver.Parse (url, out uri);
				if (uri == null) uri = url;

				MethodCallHeaderHandler mhh = new MethodCallHeaderHandler(uri);
				requestMsg = (IMessage) _binaryCore.Deserializer.Deserialize (requestStream, new HeaderHandler(mhh.HandleHeaders));

				res = next_sink.ProcessMessage (sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream);
			}
			catch (Exception ex)
			{
				responseMsg = new ReturnMessage (ex, (IMethodCallMessage)requestMsg);
				res = ServerProcessing.Complete;
				responseHeaders = null;
				responseStream = null;
			}
			
			if (res == ServerProcessing.Complete)
			{
				for (int n=0; n<3; n++) {
					responseStream = null;
					responseHeaders = new TransportHeaders();

					if (sinkStack != null) responseStream = sinkStack.GetResponseStream (responseMsg, responseHeaders);
					if (responseStream == null) responseStream = new MemoryStream();

					try {
						_binaryCore.Serializer.Serialize (responseStream, responseMsg);
						break;
					} catch (Exception ex) {
						if (n == 2) throw ex;
						else responseMsg = new ReturnMessage (ex, (IMethodCallMessage)requestMsg);
					}
				}
				
				if (responseStream is MemoryStream) responseStream.Position = 0;
				

				sinkStack.Pop (this);
			}
			return res;
		}
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            ServerProcessing serverProcessing;
            string           str;

            sinkStack.Push(this, null);
            try
            {
                string item = (string)requestHeaders["__RequestUri"];
                this.receiver.Parse(item, out str);
                if (str == null)
                {
                    str = item;
                }
                MethodCallHeaderHandler methodCallHeaderHandler = new MethodCallHeaderHandler(str);
                requestMsg       = (IMessage)this._binaryCore.Deserializer.Deserialize(requestStream, new HeaderHandler(methodCallHeaderHandler.HandleHeaders));
                serverProcessing = this.next_sink.ProcessMessage(sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream);
            }
            catch (Exception exception)
            {
                responseMsg      = new ReturnMessage(exception, (IMethodCallMessage)requestMsg);
                serverProcessing = ServerProcessing.Complete;
                responseHeaders  = null;
                responseStream   = null;
            }
            if (serverProcessing == ServerProcessing.Complete)
            {
                for (int i = 0; i < 3; i++)
                {
                    responseStream  = null;
                    responseHeaders = new TransportHeaders();
                    if (sinkStack != null)
                    {
                        responseStream = sinkStack.GetResponseStream(responseMsg, responseHeaders);
                    }
                    if (responseStream == null)
                    {
                        responseStream = new MemoryStream();
                    }
                    try
                    {
                        this._binaryCore.Serializer.Serialize(responseStream, responseMsg);
                        break;
                    }
                    catch (Exception exception2)
                    {
                        Exception exception1 = exception2;
                        if (i == 2)
                        {
                            throw exception1;
                        }
                        responseMsg = new ReturnMessage(exception1, (IMethodCallMessage)requestMsg);
                    }
                }
                if (responseStream is MemoryStream)
                {
                    responseStream.Position = (long)0;
                }
                sinkStack.Pop(this);
            }
            return(serverProcessing);
        }
		public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
							IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream,
							out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
		{
			sinkStack.Push (this, null);
			ServerProcessing res;

			try
			{
				string url = (string)requestHeaders["__RequestUri"];
				string uri;
				receiver.Parse (url, out uri);
				if (uri == null) uri = url;

				MethodCallHeaderHandler mhh = new MethodCallHeaderHandler(uri);
				requestMsg = (IMessage) _binaryCore.Deserializer.Deserialize (requestStream, new HeaderHandler(mhh.HandleHeaders));

				res = next_sink.ProcessMessage (sinkStack, requestMsg, requestHeaders, null, out responseMsg, out responseHeaders, out responseStream);
			}
			catch (Exception ex)
			{
				responseMsg = new ReturnMessage (ex, (IMethodCallMessage)requestMsg);
				res = ServerProcessing.Complete;
				responseHeaders = null;
				responseStream = null;
			}
			
			if (res == ServerProcessing.Complete)
			{
				for (int n=0; n<3; n++) {
					responseStream = null;
					responseHeaders = new TransportHeaders();

					if (sinkStack != null) responseStream = sinkStack.GetResponseStream (responseMsg, responseHeaders);
					if (responseStream == null) responseStream = new MemoryStream();

					try {
						_binaryCore.Serializer.Serialize (responseStream, responseMsg);
						break;
					} catch (Exception ex) {
						if (n == 2) throw ex;
						else responseMsg = new ReturnMessage (ex, (IMethodCallMessage)requestMsg);
					}
				}
				
				if (responseStream is MemoryStream) responseStream.Position = 0;
				

				sinkStack.Pop (this);
			}
			return res;
		}