public void TestLocateRequestDeserialisation() { MemoryStream sourceStream = new MemoryStream(); // prepare msg uint requestId = 5; 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((byte)GiopMsgTypes.LocateRequest); // msg-length cdrOut.WriteULong(22); // request-id cdrOut.WriteULong(requestId); // target: key type cdrOut.WriteULong(0); cdrOut.WriteULong(10); // key length byte[] objectKey = new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }; // testobject cdrOut.WriteOpaque(objectKey); // 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); // deserialise request message LocateRequestMessage result = m_handler.ParseIncomingLocateRequestMessage(sourceStream); // now check if values are correct Assert.IsTrue(result != null, "deserialised message is null"); Assert.AreEqual(requestId, result.RequestId); Assert.NotNull(result.ObjectKey); Assert.NotNull(result.TargetUri); Assert.AreEqual("testobject", result.TargetUri); }
private Stream PrepareLocationFwdStream(string host, ushort port, MarshalByRefObject target) { // loc fwd ior byte[] objectKey = IorUtil.GetObjectKeyForObj(target); string repositoryID = Repository.GetRepositoryID(target.GetType()); // this server support GIOP 1.2 --> create an GIOP 1.2 profile InternetIiopProfile profile = new InternetIiopProfile(new GiopVersion(1, 2), host, port, objectKey); profile.AddTaggedComponent(Services.CodeSetService.CreateDefaultCodesetComponent(m_codec)); Ior locFwdTarget = new Ior(repositoryID, new IorProfile[] { profile }); CdrOutputStreamImpl iorStream = new CdrOutputStreamImpl(new MemoryStream(), 0, new GiopVersion(1, 2)); locFwdTarget.WriteToStream(iorStream); uint encodedIorLength = (uint)iorStream.GetPosition(); // create the location fwd 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(28 + encodedIorLength); // request-id cdrOut.WriteULong(5); // reply-status: location fwd cdrOut.WriteULong(3); // one service context to enforce alignement requirement for giop 1.2 cdrOut.WriteULong(1); cdrOut.WriteULong(162739); // service context id cdrOut.WriteULong(2); // length of svc context cdrOut.WriteBool(true); cdrOut.WriteBool(false); // svc context end // body: 8 aligned cdrOut.ForceWriteAlign(Aligns.Align8); locFwdTarget.WriteToStream(cdrOut); sourceStream.Seek(0, SeekOrigin.Begin); return(sourceStream); }
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 TestLocateRequestDeserialisation() { MemoryStream sourceStream = new MemoryStream(); // prepare msg uint requestId = 5; 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((byte)GiopMsgTypes.LocateRequest); // msg-length cdrOut.WriteULong(22); // request-id cdrOut.WriteULong(requestId); // target: key type cdrOut.WriteULong(0); cdrOut.WriteULong(10); // key length byte[] objectKey = new byte[] { 116, 101, 115, 116, 111, 98, 106, 101, 99, 116 }; // testobject cdrOut.WriteOpaque(objectKey); // 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); // deserialise request message LocateRequestMessage result = m_handler.ParseIncomingLocateRequestMessage(sourceStream); // now check if values are correct Assert.IsTrue(result != null, "deserialised message is null"); Assert.AreEqual(requestId, result.RequestId); Assert.NotNull(result.ObjectKey); Assert.NotNull(result.TargetUri); Assert.AreEqual("testobject", result.TargetUri); }
private Stream PrepareLocationFwdStream(string host, ushort port, MarshalByRefObject target) { // loc fwd ior byte[] objectKey = IorUtil.GetObjectKeyForObj(target); string repositoryID = Repository.GetRepositoryID(target.GetType()); // this server support GIOP 1.2 --> create an GIOP 1.2 profile InternetIiopProfile profile = new InternetIiopProfile(new GiopVersion(1, 2), host, port, objectKey); profile.AddTaggedComponent(Services.CodeSetService.CreateDefaultCodesetComponent(m_codec)); Ior locFwdTarget = new Ior(repositoryID, new IorProfile[] { profile }); CdrOutputStreamImpl iorStream = new CdrOutputStreamImpl(new MemoryStream(), 0, new GiopVersion(1, 2)); locFwdTarget.WriteToStream(iorStream); uint encodedIorLength = (uint)iorStream.GetPosition(); // create the location fwd 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(28 + encodedIorLength); // request-id cdrOut.WriteULong(5); // reply-status: location fwd cdrOut.WriteULong(3); // one service context to enforce alignement requirement for giop 1.2 cdrOut.WriteULong(1); cdrOut.WriteULong(162739); // service context id cdrOut.WriteULong(2); // length of svc context cdrOut.WriteBool(true); cdrOut.WriteBool(false); // svc context end // body: 8 aligned cdrOut.ForceWriteAlign(Aligns.Align8); locFwdTarget.WriteToStream(cdrOut); sourceStream.Seek(0, SeekOrigin.Begin); return sourceStream; }
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]); }
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]); }