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