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); }
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); }
public void TestRequestDeserialisation() { MemoryStream sourceStream = new MemoryStream(); // prepare msg uint requestId = 5; byte responseFlags = 3; string methodName = "Add"; int nrOfArgs = 2; int arg1 = 1; int arg2 = 2; GiopVersion version = new GiopVersion(1, 2); CdrOutputStreamImpl cdrOut = new CdrOutputStreamImpl(sourceStream, 0, version); cdrOut.WriteOpaque(m_giopMagic); // version cdrOut.WriteOctet(version.Major); cdrOut.WriteOctet(version.Minor); // flags cdrOut.WriteOctet(0); // msg-type: request cdrOut.WriteOctet(0); // msg-length cdrOut.WriteULong(68); // request-id cdrOut.WriteULong(requestId); // response-flags cdrOut.WriteOctet(responseFlags); cdrOut.WritePadding(3); // target: key type cdrOut.WriteULong(0); cdrOut.WriteULong(10); // key length cdrOut.WriteOpaque(new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }); // testobject // method name cdrOut.WriteString(methodName); // no service contexts cdrOut.WriteULong(0); cdrOut.ForceWriteAlign(Aligns.Align8); // parameters cdrOut.WriteLong(arg1); cdrOut.WriteLong(arg2); // create a connection context: this is needed for request deserialisation GiopConnectionDesc conDesc = new GiopConnectionDesc(null, null); // go to stream begin sourceStream.Seek(0, SeekOrigin.Begin); IMessage result = null; TestService service = new TestService(); try { // object which should be called string uri = "testobject"; RemotingServices.Marshal(service, uri); // deserialise request message result = m_handler.ParseIncomingRequestMessage(sourceStream, conDesc); } catch (RequestDeserializationException e) { throw e; } finally { RemotingServices.Disconnect(service); } // now check if values are correct Assert.IsTrue(result != null, "deserialised message is null"); Assert.AreEqual(requestId, result.Properties[SimpleGiopMsg.REQUEST_ID_KEY]); Assert.AreEqual(version, result.Properties[SimpleGiopMsg.GIOP_VERSION_KEY]); Assert.AreEqual(responseFlags, result.Properties[SimpleGiopMsg.RESPONSE_FLAGS_KEY]); Assert.AreEqual("testobject", result.Properties[SimpleGiopMsg.URI_KEY]); Assert.AreEqual("Ch.Elca.Iiop.Tests.TestService", result.Properties[SimpleGiopMsg.TYPENAME_KEY]); Assert.AreEqual(methodName, result.Properties[SimpleGiopMsg.METHODNAME_KEY]); object[] args = (object[])result.Properties[SimpleGiopMsg.ARGS_KEY]; Assert.IsTrue(args != null, "args is null"); Assert.AreEqual(nrOfArgs, args.Length); Assert.AreEqual(arg1, args[0]); Assert.AreEqual(arg2, args[1]); }