Beispiel #1
0
        private IMessage SyncProcessMessageOnce(IMessage msg,
                                                Ior target)
        {
            IIorProfile selectedProfile;
            uint        reqId;

            try {
                // allocate (reserve) connection
                GiopClientConnectionDesc conDesc =
                    AllocateConnection(msg, target, out selectedProfile, out reqId);
                ITransportHeaders requestHeaders;
                Stream            requestStream;
                SerialiseRequest(msg, selectedProfile, conDesc, reqId,
                                 out requestHeaders, out requestStream);

                // pass the serialised GIOP-request to the first stream handling sink
                // when the call returns, the response message has been received
                ITransportHeaders responseHeaders;
                Stream            responseStream;
                m_nextSink.ProcessMessage(msg, requestHeaders, requestStream,
                                          out responseHeaders, out responseStream);

                // now deserialise the response
                return(DeserialiseResponse(responseStream,
                                           responseHeaders, msg, conDesc));
            } finally {
                m_conManager.RequestOnConnectionCompleted(msg); // release the connection, because this interaction is complete
            }
        }
Beispiel #2
0
        private void AsyncProcessMessageOnce(IMessage msg,
                                             Ior target, IMessageSink replySink)
        {
            IIorProfile selectedProfile;
            uint        reqId;

            try {
                // allocate (reserve) connection
                GiopClientConnectionDesc conDesc = AllocateConnection(msg, target, out selectedProfile, out reqId);
                SimpleGiopMsg.SetMessageAsyncRequest(msg); // mark message as async, needed for portable interceptors
                ITransportHeaders requestHeaders;
                Stream            requestStream;
                SerialiseRequest(msg, selectedProfile, conDesc, reqId,
                                 out requestHeaders, out requestStream);
                // pass the serialised GIOP-request to the first stream handling sink
                // this sink is the last sink in the message handling sink chain, therefore the reply sink chain of all the previous message handling
                // sink is passed to the ClientChannelSinkStack, which will inform this chain of the received reply
                ClientChannelSinkStack clientSinkStack = new ClientChannelSinkStack(replySink);
                AsyncProcessingData    asyncData       = new AsyncProcessingData(msg, conDesc);
                clientSinkStack.Push(this, asyncData); // push the formatter onto the sink stack, to get the chance to handle the incoming reply stream
                // forward the message to the next sink
                m_nextSink.AsyncProcessRequest(clientSinkStack, msg, requestHeaders, requestStream);
                // for oneway messages, release the connections for future use
                if ((msg is IMethodCallMessage) && GiopMessageHandler.IsOneWayCall((IMethodCallMessage)msg))
                {
                    m_conManager.RequestOnConnectionCompleted(msg);  // release the connection, because this interaction is complete
                }
            } catch {
                // release the connection, if something went wrong during connection allocation and send
                m_conManager.RequestOnConnectionCompleted(msg); // release the connection, because this interaction is complete
                throw;
            }
        }
Beispiel #3
0
 protected void Initalize(string connectionKey, GiopTransportMessageHandler transportHandler,
                          GiopClientConnectionDesc assocDesc)
 {
     m_connectionKey    = connectionKey;
     m_assocDesc        = assocDesc;
     m_transportHandler = transportHandler;
 }
Beispiel #4
0
        /// <param name="connectionKey">the key describing the connection</param>
        internal GiopBidirInitiatedConnection(string connectionKey, GiopTransportMessageHandler transportHandler,
                                              GiopClientConnectionManager conManager)
        {
            GiopRequestNumberGenerator reqNumberGen =
                new GiopRequestNumberGenerator(false);     // not connection originator -> create non-even req. numbers
            GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(conManager, this, reqNumberGen,
                                                                            transportHandler);

            Initalize(connectionKey, transportHandler, conDesc);
        }
Beispiel #5
0
        /// <param name="connectionKey">the key describing the connection</param>
        /// <param name="transport">a not yet connected client transport</param>
        /// <param name="headerFlags">the header flags to use for transport related giop messages.</param>
        internal GiopClientInitiatedConnection(string connectionKey, IClientTransport transport,
                                               MessageTimeout requestTimeOut, GiopClientConnectionManager conManager,
                                               bool supportBidir, byte headerFlags)
        {
            GiopRequestNumberGenerator reqNumberGen =
                (!supportBidir ? new GiopRequestNumberGenerator() : new GiopRequestNumberGenerator(true));
            GiopTransportMessageHandler handler =
                new GiopTransportMessageHandler(transport, requestTimeOut, headerFlags);
            GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(conManager, this, reqNumberGen, handler);

            m_clientTransport = transport;
            Initalize(connectionKey, handler, conDesc);
        }
Beispiel #6
0
 /// <summary>serialises the .NET msg to a GIOP-message</summary>
 private void SerialiseRequest(IMessage msg, IIorProfile target, GiopClientConnectionDesc conDesc,
                               uint reqId,
                               out ITransportHeaders headers, out Stream stream)
 {
     headers = new TransportHeaders();
     headers[GiopClientConnectionDesc.CLIENT_TR_HEADER_KEY] = conDesc;
     // get the stream into which the message should be serialied from the first stream handling
     // sink in the stream handling chain
     stream = m_nextSink.GetRequestStream(msg, headers);
     if (stream == null)              // the next sink delegated the decision to which stream the message should be serialised to this sink
     {
         stream = new MemoryStream(); // create a new stream
     }
     m_messageHandler.SerialiseOutgoingRequestMessage(msg, target, conDesc, stream, reqId);
 }
Beispiel #7
0
        public void AsyncProcessResponse(IClientResponseChannelSinkStack sinkStack, object state,
                                         ITransportHeaders headers, Stream stream)
        {
            // client side formatter is the last sink in the chain accessing the serialised message, therefore this method is called on the return path
            AsyncProcessingData asyncData  = (AsyncProcessingData)state; // retrieve the request msg stored on the channelSinkStack
            IMessage            requestMsg = asyncData.RequestMsg;

            try {
                IMessage responseMsg;
                try {
                    GiopClientConnectionDesc conDesc = (GiopClientConnectionDesc)asyncData.ConDesc;
                    responseMsg = DeserialiseResponse(stream, headers,
                                                      requestMsg, conDesc);
                } finally {
                    m_conManager.RequestOnConnectionCompleted(requestMsg); // release the connection, because this interaction is complete
                }
                sinkStack.DispatchReplyMessage(responseMsg);               // dispatch the result message to the message handling reply sink chain
            } catch (Exception e) {
                sinkStack.DispatchException(e);                            // dispatch the exception to the message handling reply sink chain
            }
        }
Beispiel #8
0
 /// <summary>deserialises an IIOP-msg from the response stream</summary>
 /// <returns> the .NET message created from the IIOP-msg</returns>
 internal IMessage DeserialiseResponse(Stream responseStream,
                                       ITransportHeaders headers,
                                       IMessage requestMsg,
                                       GiopClientConnectionDesc conDesc)
 {
     // stream won't be needed any more
     using (responseStream) {
         IMessage result = m_messageHandler.ParseIncomingReplyMessage(responseStream,
                                                                      (IMethodCallMessage)requestMsg,
                                                                      conDesc);
         MarshalByRefObject fwdToTarget;
         if (GiopMessageHandler.IsLocationForward(result, out fwdToTarget))
         {
             // location-fwd
             // reissue request to new target
             result = m_messageHandler.ForwardRequest((IMethodCallMessage)requestMsg,
                                                      fwdToTarget);
         }
         return(result);
     }
 }
 /// <summary>configures a client initiated connection to receive callbacks.</summary>
 /// <remarks>for use case (2)</remarks>
 internal void SetupConnectionForBidirReception(GiopClientConnectionDesc conDesc)
 {
     if (m_receptionHandler != null)
     {
         if (conDesc.Connection is GiopClientInitiatedConnection)
         {
             GiopTransportMessageHandler handler =
                 conDesc.Connection.TransportHandler;
             handler.InstallReceiver(m_receptionHandler, conDesc,
                                     m_serverThreadsMaxPerConnection); // set, if not yet set.
         }
         else
         {
             throw new INTERNAL(545, CompletionStatus.Completed_MayBe);
         }
     }
     else
     {
         throw new INTERNAL(544, CompletionStatus.Completed_MayBe);
     }
 }
        public void TestRequestSerialisation() {
            // prepare message
            MethodInfo methodToCall = typeof(TestService).GetMethod("Add");
            object[] args = new object[] { ((Int32) 1), ((Int32) 2) };
            string uri = "iiop://localhost:8087/testuri"; // Giop 1.2 will be used because no version spec in uri
            Ior target = m_iiopUrlUtil.CreateIorForUrl(uri, "");
            TestMessage msg = new TestMessage(methodToCall, args, uri);
            // prepare connection context
            GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null,
                                                                            new GiopRequestNumberGenerator(), null);

            // serialise
            MemoryStream targetStream = new MemoryStream();
 
            uint reqId = 5;
            m_handler.SerialiseOutgoingRequestMessage(msg, target.Profiles[0], conDesc, targetStream, reqId);
 
            // check to serialised stream
            targetStream.Seek(0, SeekOrigin.Begin);
 
            CdrInputStreamImpl cdrIn = new CdrInputStreamImpl(targetStream);
            cdrIn.ConfigStream(0, new GiopVersion(1, 2));
 
            // first is Giop-magic
            byte data;
            AssertBytesFollowing(m_giopMagic, cdrIn);
            // Giop version
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(1, data);
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(2, data);
            // flags: big-endian, no fragements
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(0, data);
            // Giop Msg type: request
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(0, data);
            // Giop Msg length
            uint msgLength = cdrIn.ReadULong();
            cdrIn.SetMaxLength(msgLength);
            // req-id
            Assert.AreEqual(reqId, cdrIn.ReadULong());
            // response flags
            data = (byte) cdrIn.ReadOctet();
            Assert.AreEqual(3, data);
            cdrIn.ReadPadding(3); // reserved
            // target
            Assert.AreEqual(0, cdrIn.ReadUShort());
            // target must be testuri encoded as ascii-characters
            Assert.AreEqual(7 , cdrIn.ReadULong());
            AssertBytesFollowing(
                new byte[] { 116, 101, 115, 116, 117, 114, 105 },
                cdrIn);
            // now the target method follows: Add (string is terminated by a zero)
            Assert.AreEqual(4, cdrIn.ReadULong());
            AssertBytesFollowing(new byte[] { 65, 100, 100, 0}, cdrIn);
            // now service contexts are following
            SkipServiceContexts(cdrIn);
            // Giop 1.2, must be aligned on 8
            cdrIn.ForceReadAlign(Aligns.Align8);
            // now params are following
            Assert.AreEqual(1, cdrIn.ReadLong());
            Assert.AreEqual(2, cdrIn.ReadLong());
        }
Beispiel #11
0
 /// <param name="connectionKey">the key describing the connection</param>        
 internal GiopBidirInitiatedConnection(string connectionKey, GiopTransportMessageHandler transportHandler,
                                       GiopClientConnectionManager conManager)
 {
     GiopRequestNumberGenerator reqNumberGen =
             new GiopRequestNumberGenerator(false); // not connection originator -> create non-even req. numbers
     GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(conManager, this, reqNumberGen,
                                                                     transportHandler);
     Initalize(connectionKey, transportHandler, conDesc);
 }
 /// <summary>configures a client initiated connection to receive callbacks.</summary>
 /// <remarks>for use case (2)</remarks>
 internal void SetupConnectionForBidirReception(GiopClientConnectionDesc conDesc) {
     if (m_receptionHandler != null) {
         if (conDesc.Connection is GiopClientInitiatedConnection) {
             GiopTransportMessageHandler handler =
                 conDesc.Connection.TransportHandler;
             handler.InstallReceiver(m_receptionHandler, conDesc,
                                     m_serverThreadsMaxPerConnection); // set, if not yet set.
         } else {
             throw new INTERNAL(545, CompletionStatus.Completed_MayBe);
         }
     }  else {
         throw new INTERNAL(544, CompletionStatus.Completed_MayBe);
     }
 }
        public void TestLocationForwardOnIsA() {
            // tests location forward, if we forward on is_a call
            IiopChannel chan = new IiopChannel(8090);
            ChannelServices.RegisterChannel(chan, false);
            // publish location fwd target
            TestService target = new TestService();
            string fwdTargetUri = "testuriFwdForIsA";
            RemotingServices.Marshal(target, fwdTargetUri);
 
            // request msg the reply is for
            MethodInfo methodToCall = typeof(omg.org.CORBA.IObject).GetMethod("_is_a");
            object[] args = new object[] { "IDL:Ch/Elca/Iiop/Tests/TestService:1.0" };
            string origUrl = "iiop://localhost:8090/testuri"; // Giop 1.2 will be used because no version spec in uri
            TestMessage requestMsg = new TestMessage(methodToCall, args, origUrl);
            // prepare connection desc
            GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null, new GiopRequestNumberGenerator(), null);
 
            try {
                Stream locFwdStream = PrepareLocationFwdStream("localhost", 8090,
                                                               target);
 
                IMessage resultMsg =
                    m_handler.ParseIncomingReplyMessage(locFwdStream, requestMsg, conDesc);
                MarshalByRefObject fwdToTarget;
                bool isFwd = GiopMessageHandler.IsLocationForward(resultMsg, out fwdToTarget);
                Assert.IsTrue(isFwd, "is a forward?");
                Assert.NotNull(fwdToTarget,"new target reference null?");
                ReturnMessage result = (ReturnMessage)
                    m_handler.ForwardRequest(requestMsg, fwdToTarget);
                Assert.AreEqual(true, result.ReturnValue);
                Assert.AreEqual(0, result.OutArgCount);
            } finally {
                // unpublish target + channel
                RemotingServices.Disconnect(target);
                chan.StopListening(null);
                ChannelServices.UnregisterChannel(chan);
            }

 
 
        }
Beispiel #14
0
 /// <param name="connectionKey">the key describing the connection</param>
 /// <param name="transport">a not yet connected client transport</param>
 /// <param name="headerFlags">the header flags to use for transport related giop messages.</param>
 internal GiopClientInitiatedConnection(string connectionKey, IClientTransport transport,
                                        MessageTimeout requestTimeOut, GiopClientConnectionManager conManager,
                                        bool supportBidir, byte headerFlags)
 {
     GiopRequestNumberGenerator reqNumberGen =
         (!supportBidir ? new GiopRequestNumberGenerator() : new GiopRequestNumberGenerator(true));
     GiopTransportMessageHandler handler =
               new GiopTransportMessageHandler(transport, requestTimeOut, headerFlags);
     GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(conManager, this, reqNumberGen, handler);
     m_clientTransport = transport;
     Initalize(connectionKey, handler, conDesc);
 }
 public void TestWCharSetDefinedClient() {
     MethodInfo methodToCall =
         typeof(TestStringInterface).GetMethod("EchoWString");
     object[] args = new object[] { "test" };
     string uri = "iiop://localhost:8087/testuri"; // Giop 1.2 will be used because no version spec in uri
     Ior target = m_iiopUrlUtil.CreateIorForUrl(uri, "");
     IIorProfile targetProfile = target.Profiles[0];
     TestMessage msg = new TestMessage(methodToCall, args, uri);
     msg.Properties[SimpleGiopMsg.REQUEST_ID_KEY] = (uint)5; // set request-id
     msg.Properties[SimpleGiopMsg.TARGET_PROFILE_KEY] = targetProfile;
     
     // prepare connection context
     GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null, 
                                                                     new GiopRequestNumberGenerator(), null);
                 
     GiopMessageBodySerialiser ser = new GiopMessageBodySerialiser(
                                         new ArgumentsSerializerFactory(m_serFactory));
     GiopClientRequest request = 
         new GiopClientRequest(msg, conDesc,
                               new IInterceptionOption[0]);
     MemoryStream baseStream = new MemoryStream();
     CdrOutputStreamImpl targetStream =
         new CdrOutputStreamImpl(baseStream, 0, new GiopVersion(1,2));
     ser.SerialiseRequest(request, targetStream, targetProfile,
                          conDesc);
     
     Assert.AreEqual(
         new byte[] { 0, 0, 0, 5, 3, 0, 0, 0,
                      0, 0, 0, 0, 
                      0, 0, 0, 7, 116, 101, 115, 116,
                      117, 114, 105, 0,
                      0, 0, 0, 12, 69, 99, 104, 111, 
                      87, 83, 116, 114, 105, 110, 103, 0,
                      0, 0, 0, 1, 0, 0, 0, 1,
                      0, 0, 0, 12, 1, 0, 0, 0,
                      0, 1, 0, 1, 0, 1, 1, 9,
                      0, 0, 0, 8, 0, 116, 0, 101,
                      0, 115, 0, 116},
         baseStream.ToArray(),"serialised message");
 }
 public void TestWCharSetNotDefinedClient() {
     MethodInfo methodToCall =
         typeof(TestStringInterface).GetMethod("EchoWString");
     object[] args = new object[] { "test" };
     string uri = 
         "IOR:000000000000000100000000000000010000000000000020000102000000000A6C6F63616C686F73740004D2000000047465737400000000";
     Ior target = m_iiopUrlUtil.CreateIorForUrl(uri, "");
     IIorProfile targetProfile = target.Profiles[0];
     TestMessage msg = new TestMessage(methodToCall, args, uri);
     msg.Properties[SimpleGiopMsg.REQUEST_ID_KEY] = (uint)5; // set request-id
     msg.Properties[SimpleGiopMsg.TARGET_PROFILE_KEY] = targetProfile;
     
     // prepare connection context
     GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null, 
                                                                     new GiopRequestNumberGenerator(), null);
     
     GiopMessageBodySerialiser ser = new GiopMessageBodySerialiser(
                                         new ArgumentsSerializerFactory(m_serFactory));
     GiopClientRequest request = 
         new GiopClientRequest(msg, conDesc,
                               new IInterceptionOption[0]);
     CdrOutputStreamImpl targetStream = 
         new CdrOutputStreamImpl(new MemoryStream(), 0, new GiopVersion(1,2));
     ser.SerialiseRequest(request, targetStream, targetProfile,
                          conDesc);
 }
 /// <summary>deserialises an IIOP-msg from the response stream</summary>
 /// <returns> the .NET message created from the IIOP-msg</returns>
 internal IMessage DeserialiseResponse(Stream responseStream,
                                       ITransportHeaders headers,
                                       IMessage requestMsg,
                                       GiopClientConnectionDesc conDesc) {
     // stream won't be needed any more
     using (responseStream) {
         IMessage result = m_messageHandler.ParseIncomingReplyMessage(responseStream,
                                       (IMethodCallMessage) requestMsg,
                                       conDesc);
         MarshalByRefObject fwdToTarget;
         if (GiopMessageHandler.IsLocationForward(result, out fwdToTarget)) {
             // location-fwd
             // reissue request to new target
             result = m_messageHandler.ForwardRequest((IMethodCallMessage) requestMsg,
                                                      fwdToTarget);
         }
         return result;
     }
 }
 /// <summary>serialises the .NET msg to a GIOP-message</summary>
 private void SerialiseRequest(IMessage msg, IIorProfile target, GiopClientConnectionDesc conDesc,
                               uint reqId,
                               out ITransportHeaders headers, out Stream stream) {
     headers = new TransportHeaders();
     headers[GiopClientConnectionDesc.CLIENT_TR_HEADER_KEY] = conDesc;
     // get the stream into which the message should be serialied from the first stream handling
     // sink in the stream handling chain
     stream = m_nextSink.GetRequestStream(msg, headers);
     if (stream == null) { // the next sink delegated the decision to which stream the message should be serialised to this sink
         stream = new MemoryStream(); // create a new stream
     }
     m_messageHandler.SerialiseOutgoingRequestMessage(msg, target, conDesc, stream, reqId);
 }
 public void TestReplyDeserialisation() {
     // request msg the reply is for
     MethodInfo methodToCall = typeof(TestService).GetMethod("Add");
     object[] args = new object[] { ((Int32) 1), ((Int32) 2) };
     string uri = "iiop://localhost:8087/testuri"; // Giop 1.2 will be used because no version spec in uri
     TestMessage requestMsg = new TestMessage(methodToCall, args, uri);
     requestMsg.Properties[SimpleGiopMsg.IDL_METHOD_NAME_KEY] = methodToCall.Name; // done by serialization normally
     // prepare connection desc
     GiopClientConnectionDesc conDesc = new GiopClientConnectionDesc(null, null, new GiopRequestNumberGenerator(), null);
     // create the reply
     MemoryStream sourceStream = new MemoryStream();
     CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(sourceStream, 0, new GiopVersion(1, 2));
     cdrOut.WriteOpaque(m_giopMagic);
     // version
     cdrOut.WriteOctet(1);
     cdrOut.WriteOctet(2);
     // flags
     cdrOut.WriteOctet(0);
     // msg-type: reply
     cdrOut.WriteOctet(1);
     // msg-length
     cdrOut.WriteULong(16);
     // request-id
     cdrOut.WriteULong(5);
     // reply-status: no-exception
     cdrOut.WriteULong(0);
     // no service contexts
     cdrOut.WriteULong(0);
     // body: 8 aligned
     cdrOut.ForceWriteAlign(Aligns.Align8);
     // result
     cdrOut.WriteLong(3);
     // check deser of msg:
     sourceStream.Seek(0, SeekOrigin.Begin);
     ReturnMessage result = (ReturnMessage) m_handler.ParseIncomingReplyMessage(sourceStream, requestMsg, conDesc);
     Assert.AreEqual(3, result.ReturnValue);
     Assert.AreEqual(0, result.OutArgCount);
 }
Beispiel #20
0
 protected void Initalize(string connectionKey, GiopTransportMessageHandler transportHandler,
                          GiopClientConnectionDesc assocDesc)
 {
     m_connectionKey = connectionKey;
     m_assocDesc = assocDesc;
     m_transportHandler = transportHandler;
 }