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