Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void TestAddTaggedComponent()
        {
            CodeSetComponentData codeSetCompVal =
                new CodeSetComponentData((int)CharSet.LATIN1,
                                         new int[] { (int)CharSet.LATIN1 },
                                         (int)WCharSet.UTF16,
                                         new int[] { (int)WCharSet.UTF16 });
            TaggedComponent codeSetComponent =
                new TaggedComponent(TAG_CODE_SETS.ConstVal,
                                    m_codec.encode_value(codeSetCompVal));

            m_profile.AddTaggedComponent(codeSetComponent);
            Assert.AreEqual(1, m_profile.TaggedComponents.Count, "tagged components one entry");
            Assert.IsTrue(m_profile.ContainsTaggedComponent(TAG_CODE_SETS.ConstVal), "not found code set component");
            CodeSetComponentData retrieved =
                (CodeSetComponentData)m_profile.TaggedComponents.GetComponentData(TAG_CODE_SETS.ConstVal,
                                                                                  m_codec,
                                                                                  CodeSetComponentData.TypeCode);

            Assert.NotNull(retrieved, "not found code set component");
            Assert.AreEqual(codeSetCompVal.NativeCharSet, retrieved.NativeCharSet, "char set");
            Assert.AreEqual(codeSetCompVal.NativeWCharSet, retrieved.NativeWCharSet, "wchar set");
        }