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();
                session = new TcpDuplexSession(this);                  // make sure to shutdown the session once it has initiated one.
            }
            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();
            }
        }
Exemple #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));
            }

            // 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);

            Logger.LogMessage(MessageLogSourceKind.TransportReceive, ref msg, info.BindingElement.MaxReceivedMessageSize);

            // 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));
        }
Exemple #3
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);

			Logger.LogMessage (MessageLogSourceKind.TransportReceive, ref msg, info.BindingElement.MaxReceivedMessageSize);

			// 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);
		}
Exemple #4
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 };
		}
        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
            };
        }
Exemple #6
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);
                }
            }
        }