Beispiel #1
0
        protected override void OnOpen(TimeSpan timeout)
        {
            if (!is_service_side)
            {
                NetworkStream ns = client.GetStream();
                frame = new TcpBinaryFrameManager(TcpBinaryFrameManager.DuplexMode, ns, is_service_side)
                {
                    Encoder = this.Encoder,
                    Via     = this.Via
                };
                frame.ProcessPreambleInitiator();
                frame.ProcessPreambleAckInitiator();
            }
            else
            {
                // server side
                Stream s = client.GetStream();

                frame = new TcpBinaryFrameManager(TcpBinaryFrameManager.DuplexMode, s, is_service_side)
                {
                    Encoder = this.Encoder
                };

                // FIXME: use retrieved record properties in the request processing.

                frame.ProcessPreambleRecipient();
                frame.ProcessPreambleAckRecipient();
            }
        }
Beispiel #2
0
        public override RequestContext ReceiveRequest(TimeSpan timeout)
        {
            if (timeout <= TimeSpan.Zero)
            {
                throw new ArgumentException(String.Format("Timeout value must be positive value. It was {0}", timeout));
            }

            DateTime start = DateTime.Now;

            // FIXME: use timeout
            if (client == null)
            {
                client = ((TcpChannelListener <IReplyChannel>)Manager).AcceptTcpClient(timeout);
            }
            NetworkStream ns = client.GetStream();

            frame = new TcpBinaryFrameManager(TcpBinaryFrameManager.SingletonUnsizedMode, ns, true)
            {
                Encoder = this.Encoder
            };

            // FIXME: use timeout
            if (!frame.ProcessPreambleRecipient())
            {
                return(null);
            }
            frame.ProcessPreambleAckRecipient();

            var msg = frame.ReadUnsizedMessage(timeout);

            // LAMESPEC: it contradicts the protocol explanation at section 3.1.1.1.1 in [MC-NMF].
            // Moving ReadEndRecord() after context's WriteUnsizedMessage() causes TCP connection blocking.
            frame.ReadEndRecord();
            return(new TcpRequestContext(this, msg));
        }
Beispiel #3
0
        public Message ReadSizedMessage()
        {
            // FIXME: implement full [MC-NMF].

            var packetType = s.ReadByte();

            if (packetType == EndRecord)
            {
                return(null);
            }
            if (packetType != SizedEnvelopeRecord)
            {
                throw new NotImplementedException(String.Format("Packet type {0:X} is not implemented", packetType));
            }

            byte [] buffer = ReadSizedChunk();

            var ms = new MemoryStream(buffer, 0, buffer.Length);

            // FIXME: turned out that it could be either in-band dictionary ([MC-NBFSE]), or a mere xml body ([MC-NBFS]).
            if (EncodingRecord != EncodingBinaryWithDictionary)
            {
                throw new NotImplementedException(String.Format("Message encoding {0:X} is not implemented yet", EncodingRecord));
            }

            // Encoding type 8:
            // the returned buffer consists of a serialized reader
            // session and the binary xml body.

            var session = reader_session ?? new XmlBinaryReaderSession();

            reader_session = session;
            byte [] rsbuf = new TcpBinaryFrameManager(0, ms, is_service_side).ReadSizedChunk();
            using (var rms = new MemoryStream(rsbuf, 0, rsbuf.Length)) {
                var rbr = new BinaryReader(rms, Encoding.UTF8);
                while (rms.Position < rms.Length)
                {
                    session.Add(reader_session_items++, rbr.ReadString());
                }
            }
            var benc = Encoder as BinaryMessageEncoder;

            if (benc != null)
            {
                benc.CurrentReaderSession = session;
            }

            // FIXME: supply maxSizeOfHeaders.
            Message msg = Encoder.ReadMessage(ms, 0x10000);

            if (benc != null)
            {
                benc.CurrentReaderSession = null;
            }

            return(msg);
        }
Beispiel #4
0
 protected override void OnOpen(TimeSpan timeout)
 {
     // FIXME: use timeout
     frame = new TcpBinaryFrameManager(TcpBinaryFrameManager.SingletonUnsizedMode, server, true)
     {
         Encoder = this.Encoder
     };
     frame.ProcessPreambleRecipient();
     frame.ProcessPreambleAckRecipient();
 }
Beispiel #5
0
		void CreateClient (TimeSpan timeout)
		{
			int explicitPort = Via.Port;
			client = new TcpClient (Via.Host, explicitPort <= 0 ? TcpTransportBindingElement.DefaultPort : explicitPort);
			
			NetworkStream ns = client.GetStream ();
			frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.SingletonUnsizedMode, ns, false) {
				Encoder = this.Encoder,
				Via = this.Via };
		}
Beispiel #6
0
		void CreateClient (TimeSpan timeout)
		{
			int explicitPort = Via.Port;
			var stream = new NamedPipeClientStream (".", Via.LocalPath.Substring (1).Replace ('/', '\\'), PipeDirection.InOut);
			stream.Connect ();
			frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.SingletonUnsizedMode, stream, false) {
				Encoder = this.Encoder,
				Via = this.Via };
			frame.ProcessPreambleInitiator ();
			frame.ProcessPreambleAckInitiator ();
		}
Beispiel #7
0
        void CreateClient(TimeSpan timeout)
        {
            int explicitPort = Via.Port;

            client = new TcpClient(Via.Host, explicitPort <= 0 ? TcpTransportBindingElement.DefaultPort : explicitPort);

            NetworkStream ns = client.GetStream();

            frame = new TcpBinaryFrameManager(TcpBinaryFrameManager.SingletonUnsizedMode, ns, false)
            {
                Encoder = this.Encoder,
                Via     = this.Via
            };
        }
Beispiel #8
0
        void CreateClient(TimeSpan timeout)
        {
            int explicitPort = Via.Port;
            var stream       = new NamedPipeClientStream(".", Via.LocalPath.Substring(1).Replace('/', '\\'), PipeDirection.InOut);

            stream.Connect();
            frame = new TcpBinaryFrameManager(TcpBinaryFrameManager.SingletonUnsizedMode, stream, false)
            {
                Encoder = this.Encoder,
                Via     = this.Via
            };
            frame.ProcessPreambleInitiator();
            frame.ProcessPreambleAckInitiator();
        }
Beispiel #9
0
        protected override void OnOpen(TimeSpan timeout)
        {
            // FIXME: use timeout
            if (client == null)
            {
                client = ((TcpChannelListener <IReplyChannel>)Manager).AcceptTcpClient(timeout);
            }
            NetworkStream ns = client.GetStream();

            frame = new TcpBinaryFrameManager(TcpBinaryFrameManager.SingletonUnsizedMode, ns, true)
            {
                Encoder = this.Encoder, EncodingRecord = TcpBinaryFrameManager.EncodingBinary
            };
        }
Beispiel #10
0
		public override RequestContext ReceiveRequest (TimeSpan timeout)
		{
			if (timeout <= TimeSpan.Zero)
				throw new ArgumentException (String.Format ("Timeout value must be positive value. It was {0}", timeout));

			DateTime start = DateTime.Now;

			// FIXME: use timeout
			if (client == null)
				client = ((TcpChannelListener<IReplyChannel>) Manager).AcceptTcpClient (timeout);
			NetworkStream ns = client.GetStream ();
			frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.SingletonUnsizedMode, ns, true) { Encoder = this.Encoder, EncodingRecord = TcpBinaryFrameManager.EncodingBinary };

			// FIXME: use timeout
			if (!frame.ProcessPreambleRecipient ())
				return null;
			frame.ProcessPreambleAckRecipient ();

			var msg = frame.ReadUnsizedMessage (timeout);
			// LAMESPEC: it contradicts the protocol explanation at section 3.1.1.1.1 in [MC-NMF].
			// Moving ReadEndRecord() after context's WriteUnsizedMessage() causes TCP connection blocking.
			frame.ReadEndRecord ();
			return new TcpRequestContext (this, msg);
		}
Beispiel #11
0
        public Message ReadSizedMessage()
        {
            // FIXME: implement full [MC-NMF].

            int packetType;

            try {
                packetType = s.ReadByte();
            } catch (IOException) {
                // it is already disconnected
                return(null);
            } catch (SocketException) {
                // it is already disconnected
                return(null);
            }
            // FIXME: .NET never results in -1, so there may be implementation mismatch in Socket (but might be in other places)
            if (packetType == -1)
            {
                return(null);
            }
            // FIXME: The client should wait for EndRecord, but if we try to send it, the socket blocks and becomes unable to work anymore.
            if (packetType == EndRecord)
            {
                return(null);
            }
            if (packetType != SizedEnvelopeRecord)
            {
                if (is_service_side)
                {
                    // reconnect
                    ProcessPreambleRecipient(packetType);
                    ProcessPreambleAckRecipient();
                }
                else
                {
                    throw new NotImplementedException(String.Format("Packet type {0:X} is not implemented", packetType));
                }
            }

            byte [] buffer = ReadSizedChunk();

            var ms = new MemoryStream(buffer, 0, buffer.Length);

            // FIXME: turned out that it could be either in-band dictionary ([MC-NBFSE]), or a mere xml body ([MC-NBFS]).
            if (EncodingRecord != EncodingBinaryWithDictionary)
            {
                throw new NotImplementedException(String.Format("Message encoding {0:X} is not implemented yet", EncodingRecord));
            }

            // Encoding type 8:
            // the returned buffer consists of a serialized reader
            // session and the binary xml body.

            var session = reader_session ?? new XmlBinaryReaderSession();

            reader_session = session;
            byte [] rsbuf = new TcpBinaryFrameManager(0, ms, is_service_side).ReadSizedChunk();
            using (var rms = new MemoryStream(rsbuf, 0, rsbuf.Length)) {
                var rbr = new BinaryReader(rms, Encoding.UTF8);
                while (rms.Position < rms.Length)
                {
                    session.Add(reader_session_items++, rbr.ReadString());
                }
            }
            var benc = Encoder as BinaryMessageEncoder;

            if (benc != null)
            {
                benc.CurrentReaderSession = session;
            }

            // FIXME: supply maxSizeOfHeaders.
            Message msg = Encoder.ReadMessage(ms, 0x10000);

            if (benc != null)
            {
                benc.CurrentReaderSession = null;
            }

            return(msg);
        }
Beispiel #12
0
		public Message ReadSizedMessage ()
		{
			lock (read_lock) {

			// FIXME: implement full [MC-NMF].

			int packetType;
			try {
				packetType = s.ReadByte ();
			} catch (IOException) {
				// it is already disconnected
				return null;
			} catch (SocketException) {
				// it is already disconnected
				return null;
			}
			// FIXME: .NET never results in -1, so there may be implementation mismatch in Socket (but might be in other places)
			if (packetType == -1)
				return null;
			// FIXME: The client should wait for EndRecord, but if we try to send it, the socket blocks and becomes unable to work anymore.
			if (packetType == EndRecord)
				return null;
			if (packetType != SizedEnvelopeRecord) {
				if (is_service_side) {
					// reconnect
					ProcessPreambleRecipient (packetType);
					ProcessPreambleAckRecipient ();
				}
				else
					throw new NotImplementedException (String.Format ("Packet type {0:X} is not implemented", packetType));
			}

			byte [] buffer = ReadSizedChunk ();
			var ms = new MemoryStream (buffer, 0, buffer.Length);

			// FIXME: turned out that it could be either in-band dictionary ([MC-NBFSE]), or a mere xml body ([MC-NBFS]).
			bool inBandDic = false;
			XmlBinaryReaderSession session = null;
			switch (EncodingRecord) {
			case Soap11EncodingUtf8:
			case Soap11EncodingUtf16:
			case Soap11EncodingUtf16LE:
			case Soap12EncodingUtf8:
			case Soap12EncodingUtf16:
			case Soap12EncodingUtf16LE:
				if (!(Encoder is TextMessageEncoder))
					throw new InvalidOperationException (String.Format ("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));
				break;
			case Soap12EncodingMtom:
				if (!(Encoder is MtomMessageEncoder))
					throw new InvalidOperationException (String.Format ("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));
				break;
			default:
					throw new InvalidOperationException (String.Format ("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));
			case Soap12EncodingBinaryWithDictionary:
				inBandDic = true;
				goto case Soap12EncodingBinary;
			case Soap12EncodingBinary:
				session = inBandDic ? (reader_session ?? new XmlBinaryReaderSession ()) : null;
				reader_session = session;
				if (inBandDic) {
					byte [] rsbuf = new TcpBinaryFrameManager (0, ms, is_service_side).ReadSizedChunk ();
					using (var rms = new MemoryStream (rsbuf, 0, rsbuf.Length)) {
						var rbr = new BinaryReader (rms, Encoding.UTF8);
						while (rms.Position < rms.Length)
							session.Add (reader_session_items++, rbr.ReadString ());
					}
				}
				break;
			}
			var benc = Encoder as BinaryMessageEncoder;
			lock (Encoder) {
				if (benc != null)
					benc.CurrentReaderSession = session;

				// FIXME: supply maxSizeOfHeaders.
				Message msg = Encoder.ReadMessage (ms, 0x10000);
				if (benc != null)
					benc.CurrentReaderSession = null;
				return msg;
			}
			
			}
		}
		protected override void OnOpen (TimeSpan timeout)
		{
			// FIXME: use timeout
			if (client == null)
				client = ((TcpChannelListener<IReplyChannel>) Manager).AcceptTcpClient (timeout);
			NetworkStream ns = client.GetStream ();
			frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.SingletonUnsizedMode, ns, true) { Encoder = this.Encoder, EncodingRecord = TcpBinaryFrameManager.EncodingBinary };
		}
		protected override void OnOpen (TimeSpan timeout)
		{
			if (! is_service_side) {
				NetworkStream ns = client.GetStream ();
				frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.DuplexMode, ns, is_service_side) {
					Encoder = this.Encoder,
					Via = this.Via };
				frame.ProcessPreambleInitiator ();
				frame.ProcessPreambleAckInitiator ();
			} else {
				// server side
				Stream s = client.GetStream ();

				frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.DuplexMode, s, is_service_side) { Encoder = this.Encoder };

				// FIXME: use retrieved record properties in the request processing.

				frame.ProcessPreambleRecipient ();
				frame.ProcessPreambleAckRecipient ();
			}
		}
		protected override void OnOpen (TimeSpan timeout)
		{
			DateTime start = DateTime.Now;

			// FIXME: use timeout
			frame = new TcpBinaryFrameManager (TcpBinaryFrameManager.SingletonUnsizedMode, server, true) { Encoder = this.Encoder, EncodingRecord = TcpBinaryFrameManager.EncodingBinary };
			frame.ProcessPreambleRecipient ();
			frame.ProcessPreambleAckRecipient ();
		}
Beispiel #16
0
        public Message ReadSizedMessage()
        {
            lock (read_lock) {
                // FIXME: implement full [MC-NMF].

                int packetType;
                try {
                    packetType = s.ReadByte();
                } catch (IOException) {
                    // it is already disconnected
                    return(null);
                } catch (SocketException) {
                    // it is already disconnected
                    return(null);
                }
                // FIXME: .NET never results in -1, so there may be implementation mismatch in Socket (but might be in other places)
                if (packetType == -1)
                {
                    return(null);
                }
                // FIXME: The client should wait for EndRecord, but if we try to send it, the socket blocks and becomes unable to work anymore.
                if (packetType == EndRecord)
                {
                    return(null);
                }
                if (packetType != SizedEnvelopeRecord)
                {
                    if (is_service_side)
                    {
                        // reconnect
                        ProcessPreambleRecipient(packetType);
                        ProcessPreambleAckRecipient();
                    }
                    else
                    {
                        throw new NotImplementedException(String.Format("Packet type {0:X} is not implemented", packetType));
                    }
                }

                byte [] buffer = ReadSizedChunk();
                var     ms     = new MemoryStream(buffer, 0, buffer.Length);

                // FIXME: turned out that it could be either in-band dictionary ([MC-NBFSE]), or a mere xml body ([MC-NBFS]).
                bool inBandDic = false;
                XmlBinaryReaderSession session = null;
                switch (EncodingRecord)
                {
                case Soap11EncodingUtf8:
                case Soap11EncodingUtf16:
                case Soap11EncodingUtf16LE:
                case Soap12EncodingUtf8:
                case Soap12EncodingUtf16:
                case Soap12EncodingUtf16LE:
                    if (!(Encoder is TextMessageEncoder))
                    {
                        throw new InvalidOperationException(String.Format("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));
                    }
                    break;

                case Soap12EncodingMtom:
                    if (!(Encoder is MtomMessageEncoder))
                    {
                        throw new InvalidOperationException(String.Format("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));
                    }
                    break;

                default:
                    throw new InvalidOperationException(String.Format("Unexpected message encoding value in the received message: {0:X}", EncodingRecord));

                case Soap12EncodingBinaryWithDictionary:
                    inBandDic = true;
                    goto case Soap12EncodingBinary;

                case Soap12EncodingBinary:
                    session        = inBandDic ? (reader_session ?? new XmlBinaryReaderSession()) : null;
                    reader_session = session;
                    if (inBandDic)
                    {
                        byte [] rsbuf = new TcpBinaryFrameManager(0, ms, is_service_side).ReadSizedChunk();
                        using (var rms = new MemoryStream(rsbuf, 0, rsbuf.Length)) {
                            var rbr = new BinaryReader(rms, Encoding.UTF8);
                            while (rms.Position < rms.Length)
                            {
                                session.Add(reader_session_items++, rbr.ReadString());
                            }
                        }
                    }
                    break;
                }
                var benc = Encoder as BinaryMessageEncoder;
                lock (Encoder) {
                    if (benc != null)
                    {
                        benc.CurrentReaderSession = session;
                    }

                    // FIXME: supply maxSizeOfHeaders.
                    Message msg = Encoder.ReadMessage(ms, 0x10000);
                    if (benc != null)
                    {
                        benc.CurrentReaderSession = null;
                    }
                    return(msg);
                }
            }
        }
Beispiel #17
0
		public Message ReadSizedMessage ()
		{
			lock (read_lock) {

			// FIXME: implement full [MC-NMF].

			int packetType;
			try {
				packetType = s.ReadByte ();
			} catch (IOException) {
				// it is already disconnected
				return null;
			} catch (SocketException) {
				// it is already disconnected
				return null;
			}
			// FIXME: .NET never results in -1, so there may be implementation mismatch in Socket (but might be in other places)
			if (packetType == -1)
				return null;
			// FIXME: The client should wait for EndRecord, but if we try to send it, the socket blocks and becomes unable to work anymore.
			if (packetType == EndRecord)
				return null;
			if (packetType != SizedEnvelopeRecord) {
				if (is_service_side) {
					// reconnect
					ProcessPreambleRecipient (packetType);
					ProcessPreambleAckRecipient ();
				}
				else
					throw new NotImplementedException (String.Format ("Packet type {0:X} is not implemented", packetType));
			}

			byte [] buffer = ReadSizedChunk ();

			var ms = new MemoryStream (buffer, 0, buffer.Length);

			// FIXME: turned out that it could be either in-band dictionary ([MC-NBFSE]), or a mere xml body ([MC-NBFS]).
			if (EncodingRecord != EncodingBinaryWithDictionary)
				throw new NotImplementedException (String.Format ("Message encoding {0:X} is not implemented yet", EncodingRecord));

			// Encoding type 8:
			// the returned buffer consists of a serialized reader 
			// session and the binary xml body. 

			var session = reader_session ?? new XmlBinaryReaderSession ();
			reader_session = session;
			byte [] rsbuf = new TcpBinaryFrameManager (0, ms, is_service_side).ReadSizedChunk ();
			using (var rms = new MemoryStream (rsbuf, 0, rsbuf.Length)) {
				var rbr = new BinaryReader (rms, Encoding.UTF8);
				while (rms.Position < rms.Length)
					session.Add (reader_session_items++, rbr.ReadString ());
			}
			var benc = Encoder as BinaryMessageEncoder;
			if (benc != null)
				benc.CurrentReaderSession = session;

			// FIXME: supply maxSizeOfHeaders.
			Message msg = Encoder.ReadMessage (ms, 0x10000);
			if (benc != null)
				benc.CurrentReaderSession = null;

			return msg;
			
			}
		}