Exemple #1
0
        /// <summary>reads an incoming Giop reply message from the Message input stream msgInput</summary>
        /// <remarks>Precondition: sourceStream contains a Giop reply Msg</remarks>
        /// <returns>the .NET reply Msg created from the Giop Reply</returns>
        internal IMessage ParseIncomingReplyMessage(CdrMessageInputStream msgInput,
                                                    IMethodCallMessage requestMessage,
                                                    GiopClientConnectionDesc conDesc)
        {
            Debug.WriteLine("receive reply message at client side");

            CdrInputStream    msgBody = msgInput.GetMessageContentReadingStream();
            GiopClientRequest request = new GiopClientRequest(requestMessage, conDesc, m_interceptionOptions);

            if (request.IsAsyncRequest)
            {
                try {
                    // with respec to interception, this is a new request -> call again send_request interception before reply
                    request.PrepareSecondAscyncInterception();
                    request.InterceptSendRequest();
                } catch (Exception ex) {
                    request.Reply = new ReturnMessage(ex, requestMessage);
                    Exception newException = request.InterceptReceiveException(ex);
                    if (newException == ex)
                    {
                        throw;
                    }
                    else
                    {
                        throw newException; // exeption has been changed by interception point
                    }
                }
            }
            // deserialize message body
            IMessage result = m_ser.DeserialiseReply(msgBody, msgInput.Header.Version, request,
                                                     conDesc);

            return(result);
        }
Exemple #2
0
 internal GiopClientRequest(IMethodCallMessage requestMsg, GiopClientConnectionDesc conDesc,
                            IInterceptionOption[] interceptionOptions)
 {
     m_requestMessage = requestMsg;
     m_conDesc        = conDesc;
     IntializeForInterception(interceptionOptions);
 }
Exemple #3
0
        /// <summary>reads an incoming Giop reply message from the Stream sourceStream</summary>
        /// <remarks>Precondition: sourceStream contains a Giop reply Msg</remarks>
        /// <returns>the .NET reply Msg created from the Giop Reply</returns>
        internal IMessage ParseIncomingReplyMessage(Stream sourceStream,
                                                    IMethodCallMessage requestMessage,
                                                    GiopClientConnectionDesc conDesc)
        {
            CdrMessageInputStream msgInput = new CdrMessageInputStream(sourceStream);

            return(ParseIncomingReplyMessage(msgInput, requestMessage, conDesc));
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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);
            }
        }
 internal GiopClientRequest(IMethodCallMessage requestMsg, GiopClientConnectionDesc conDesc,
                            IInterceptionOption[] interceptionOptions) {
     m_requestMessage = requestMsg;
     m_conDesc = conDesc;
     IntializeForInterception(interceptionOptions);
 }
 /// <summary>serialises an outgoing .NET request Message on client side</summary>
 internal void SerialiseOutgoingRequestMessage(IMessage msg, IIorProfile target, GiopClientConnectionDesc conDesc,
                                             Stream targetStream, uint requestId) {
     if (msg is IConstructionCallMessage) {
         // not supported in CORBA, TBD: replace through do nothing instead of exception
         throw new NotSupportedException("client activated objects are not supported with this channel");
     } else if (msg is IMethodCallMessage) {
         GiopVersion version = target.Version;
         // write a CORBA request message into the stream targetStream
         GiopHeader header = new GiopHeader(version.Major, version.Minor,
                                            m_headerFlags, GiopMsgTypes.Request);
         CdrMessageOutputStream msgOutput = new CdrMessageOutputStream(targetStream, header);
         // serialize the message, this insert some data into msg, e.g. request-id
         msg.Properties[SimpleGiopMsg.REQUEST_ID_KEY] = requestId; // set request-id
         msg.Properties[SimpleGiopMsg.TARGET_PROFILE_KEY] = target;
         GiopClientRequest request = new GiopClientRequest((IMethodCallMessage)msg, conDesc, m_interceptionOptions);
         m_ser.SerialiseRequest(request,
                                msgOutput.GetMessageContentWritingStream(),
                                target, conDesc);
         msgOutput.CloseStream();
         if ((request.IsAsyncRequest) || (request.IsOneWayCall)) {
             // after successful serialisation, call for oneway and async requests receive other,
             // see corba 2.6, page 21-12.
             request.InterceptReceiveOther();
         }
     } else {
         throw new NotImplementedException("handling for this type of .NET message is not implemented at the moment, type: " +
                                           msg.GetType());
     }
 }
        /// <summary>reads an incoming Giop reply message from the Message input stream msgInput</summary>
        /// <remarks>Precondition: sourceStream contains a Giop reply Msg</remarks>
        /// <returns>the .NET reply Msg created from the Giop Reply</returns>
        internal IMessage ParseIncomingReplyMessage(CdrMessageInputStream msgInput,
                                                  IMethodCallMessage requestMessage,
                                                  GiopClientConnectionDesc conDesc) {
            Debug.WriteLine("receive reply message at client side");
 
            CdrInputStream msgBody = msgInput.GetMessageContentReadingStream();
            GiopClientRequest request = new GiopClientRequest(requestMessage, conDesc, m_interceptionOptions);
            if (request.IsAsyncRequest) {
                try {
                    // with respec to interception, this is a new request -> call again send_request interception before reply
                    request.PrepareSecondAscyncInterception();
                    request.InterceptSendRequest();
                } catch (Exception ex) {
                    request.Reply = new ReturnMessage(ex, requestMessage);
                    Exception newException = request.InterceptReceiveException(ex);
                    if (newException == ex) {
                        throw;
                    } else {
                        throw newException; // exeption has been changed by interception point
                    }
                }
            }
            // deserialize message body
            IMessage result = m_ser.DeserialiseReply(msgBody, msgInput.Header.Version, request,
                                                     conDesc);
            return result;
        }
 /// <summary>reads an incoming Giop reply message from the Stream sourceStream</summary>
 /// <remarks>Precondition: sourceStream contains a Giop reply Msg</remarks>
 /// <returns>the .NET reply Msg created from the Giop Reply</returns>
 internal IMessage ParseIncomingReplyMessage(Stream sourceStream,
                                           IMethodCallMessage requestMessage,
                                           GiopClientConnectionDesc conDesc) {
     CdrMessageInputStream msgInput = new CdrMessageInputStream(sourceStream);
     return ParseIncomingReplyMessage(msgInput, requestMessage, conDesc);
 }
Exemple #10
0
        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());
        }
Exemple #11
0
 /// <summary>serialises an outgoing .NET request Message on client side</summary>
 internal void SerialiseOutgoingRequestMessage(IMessage msg, IIorProfile target, GiopClientConnectionDesc conDesc,
                                               Stream targetStream, uint requestId)
 {
     if (msg is IConstructionCallMessage)
     {
         // not supported in CORBA, TBD: replace through do nothing instead of exception
         throw new NotSupportedException("client activated objects are not supported with this channel");
     }
     else if (msg is IMethodCallMessage)
     {
         GiopVersion version = target.Version;
         // write a CORBA request message into the stream targetStream
         GiopHeader header = new GiopHeader(version.Major, version.Minor,
                                            m_headerFlags, GiopMsgTypes.Request);
         CdrMessageOutputStream msgOutput = new CdrMessageOutputStream(targetStream, header);
         // serialize the message, this insert some data into msg, e.g. request-id
         msg.Properties[SimpleGiopMsg.REQUEST_ID_KEY]     = requestId; // set request-id
         msg.Properties[SimpleGiopMsg.TARGET_PROFILE_KEY] = target;
         GiopClientRequest request = new GiopClientRequest((IMethodCallMessage)msg, conDesc, m_interceptionOptions);
         m_ser.SerialiseRequest(request,
                                msgOutput.GetMessageContentWritingStream(),
                                target, conDesc);
         msgOutput.CloseStream();
         if ((request.IsAsyncRequest) || (request.IsOneWayCall))
         {
             // after successful serialisation, call for oneway and async requests receive other,
             // see corba 2.6, page 21-12.
             request.InterceptReceiveOther();
         }
     }
     else
     {
         throw new NotImplementedException("handling for this type of .NET message is not implemented at the moment, type: " +
                                           msg.GetType());
     }
 }