/// <summary>
        /// Initialize RpceServerContext.
        /// </summary>
        /// <param name="protocolSequence">The RPC protocol sequence strings.</param>
        /// <param name="endpoint">The endpoint of server.</param>
        /// <param name="namedPipeTransportCredential">Credential for namepiped transport.</param>
        internal RpceServerContext(
            String protocolSequence,
            String endpoint,
            AccountCredential namedPipeTransportCredential)
        {
            this.protocolSequence             = protocolSequence;
            this.endpoint                     = endpoint;
            this.namedPipeTransportCredential = namedPipeTransportCredential;

            this.sessions     = new Dictionary <string, RpceServerSessionContext>();
            this.tempSessions = new Dictionary <string, RpceServerSessionContext>();

            //set default value
            this.maxReceiveFragmentSize  = RpceUtility.DEFAULT_MAX_RECEIVE_FRAGMENT_SIZE;
            this.maxTransmitFragmentSize = RpceUtility.DEFAULT_MAX_TRANSMIT_FRAGMENT_SIZE;
            this.rpcVersionMajor         = 5;
            this.rpcVersionMinor         = 1;
            this.ndrVersion = RpceNdrVersion.NDR;
        }
        /// <summary>
        /// Initialize RpceServerContext.
        /// </summary>
        /// <param name="protocolSequence">The RPC protocol sequence strings.</param>
        /// <param name="endpoint">The endpoint of server.</param>
        /// <param name="namedPipeTransportCredential">Credential for namepiped transport.</param>
        internal RpceServerContext(
            String protocolSequence,
            String endpoint,
            AccountCredential namedPipeTransportCredential)
        {
            this.protocolSequence = protocolSequence;
            this.endpoint = endpoint;
            this.namedPipeTransportCredential = namedPipeTransportCredential;

            this.sessions = new Dictionary<string, RpceServerSessionContext>();
            this.tempSessions = new Dictionary<string, RpceServerSessionContext>();

            //set default value
            this.maxReceiveFragmentSize = RpceUtility.DEFAULT_MAX_RECEIVE_FRAGMENT_SIZE;
            this.maxTransmitFragmentSize = RpceUtility.DEFAULT_MAX_TRANSMIT_FRAGMENT_SIZE;
            this.rpcVersionMajor = 5;
            this.rpcVersionMinor = 1;
            this.ndrVersion = RpceNdrVersion.NDR;
        }
        /// <summary>
        /// Create an RpceCoBindPdu.
        /// </summary>
        /// <param name="rpcVersionMinor">
        /// RPC version minor.
        /// </param>
        /// <param name="pfcFlags">
        /// PFC_*** flags.
        /// </param>
        /// <param name="callId">
        /// Call Id.
        /// </param>
        /// <param name="maxTransmitFragmentSize">
        /// Max transmit fragment size, in bytes.
        /// </param>
        /// <param name="maxReceiveFragmentSize">
        /// Max receive fragment size, in bytes.
        /// </param>
        /// <param name="associateGroupId">
        /// Associated group id.
        /// </param>
        /// <param name="interfaceId">
        /// A Guid of interface_id that is binding to.
        /// </param>
        /// <param name="interfaceMajorVersion">
        /// interface_major_ver that is binding to.
        /// </param>
        /// <param name="interfaceMinorVersion">
        /// interface_minor_ver that is binding to.
        /// </param>
        /// <param name="ndrVersion">
        /// NDR version to be used to marshal/un-marshal stub.
        /// </param>
        /// <param name="bindTimeFeatureNegotiationBitmask">
        /// BindTimeFeatureNegotiationBitmask to sent. 
        /// Set the value to null if client donot support the feature.
        /// </param>
        /// <returns>
        /// Created RpceCoBindPdu, it's ok to be sent out if there's 
        /// no modification to any field of the PDU.
        /// </returns>
        public RpceCoBindPdu CreateCoBindPdu(
            byte rpcVersionMinor,
            RpceCoPfcFlags pfcFlags,
            uint callId,
            ushort maxTransmitFragmentSize,
            ushort maxReceiveFragmentSize,
            uint associateGroupId,
            Guid interfaceId,
            ushort interfaceMajorVersion,
            ushort interfaceMinorVersion,
            RpceNdrVersion ndrVersion,
            RpceBindTimeFeatureNegotiationBitmask? bindTimeFeatureNegotiationBitmask)
        {
            RpceCoBindPdu bindPdu = new RpceCoBindPdu(context);

            bindPdu.rpc_vers = 5;
            bindPdu.rpc_vers_minor = rpcVersionMinor;
            bindPdu.PTYPE = RpcePacketType.Bind;
            bindPdu.pfc_flags = pfcFlags
                | RpceCoPfcFlags.PFC_FIRST_FRAG
                | RpceCoPfcFlags.PFC_LAST_FRAG;
            bindPdu.packed_drep.dataRepFormat = RpceDataRepresentationFormat.IEEE_LittleEndian_ASCII;
            bindPdu.packed_drep.reserved = 0;
            bindPdu.call_id = callId;

            bindPdu.max_xmit_frag = maxTransmitFragmentSize;
            bindPdu.max_recv_frag = maxReceiveFragmentSize;
            bindPdu.assoc_group_id = associateGroupId;

            List<p_cont_elem_t> p_cont_elem_list = new List<p_cont_elem_t>();
            if ((ndrVersion & RpceNdrVersion.NDR) == RpceNdrVersion.NDR)
            {
                p_cont_elem_t p_cont_elem;
                p_cont_elem.p_cont_id = (ushort)(p_cont_elem_list.Count);
                p_cont_elem.n_transfer_syn = 1;
                p_cont_elem.reserved = 0;
                p_cont_elem.abstract_syntax.if_uuid = interfaceId;
                p_cont_elem.abstract_syntax.if_vers_major = interfaceMajorVersion;
                p_cont_elem.abstract_syntax.if_vers_minor = interfaceMinorVersion;
                p_cont_elem.transfer_syntaxes = new p_syntax_id_t[1];
                p_cont_elem.transfer_syntaxes[0].if_uuid
                    = RpceUtility.NDR_INTERFACE_UUID;
                p_cont_elem.transfer_syntaxes[0].if_vers_major
                    = RpceUtility.NDR_INTERFACE_MAJOR_VERSION;
                p_cont_elem.transfer_syntaxes[0].if_vers_minor
                    = RpceUtility.NDR_INTERFACE_MINOR_VERSION;
                p_cont_elem_list.Add(p_cont_elem);
            }
            if ((ndrVersion & RpceNdrVersion.NDR64) == RpceNdrVersion.NDR64)
            {
                p_cont_elem_t p_cont_elem;
                p_cont_elem.p_cont_id = (ushort)(p_cont_elem_list.Count);
                p_cont_elem.n_transfer_syn = 1;
                p_cont_elem.reserved = 0;
                p_cont_elem.abstract_syntax.if_uuid = interfaceId;
                p_cont_elem.abstract_syntax.if_vers_major = interfaceMajorVersion;
                p_cont_elem.abstract_syntax.if_vers_minor = interfaceMinorVersion;
                p_cont_elem.transfer_syntaxes = new p_syntax_id_t[1];
                p_cont_elem.transfer_syntaxes[0].if_uuid
                    = RpceUtility.NDR64_INTERFACE_UUID;
                p_cont_elem.transfer_syntaxes[0].if_vers_major
                    = RpceUtility.NDR64_INTERFACE_MAJOR_VERSION;
                p_cont_elem.transfer_syntaxes[0].if_vers_minor
                    = RpceUtility.NDR64_INTERFACE_MINOR_VERSION;
                p_cont_elem_list.Add(p_cont_elem);
            }
            if (bindTimeFeatureNegotiationBitmask != null)
            {
                p_cont_elem_t p_cont_elem;
                p_cont_elem.p_cont_id = (ushort)(p_cont_elem_list.Count);
                p_cont_elem.n_transfer_syn = 1;
                p_cont_elem.reserved = 0;
                p_cont_elem.abstract_syntax.if_uuid = interfaceId;
                p_cont_elem.abstract_syntax.if_vers_major = interfaceMajorVersion;
                p_cont_elem.abstract_syntax.if_vers_minor = interfaceMinorVersion;
                p_cont_elem.transfer_syntaxes = new p_syntax_id_t[1];
                byte[] guidBytes = new byte[RpceUtility.GUID_SIZE]; // length of a Guid
                Buffer.BlockCopy(
                    RpceUtility.BIND_TIME_FEATURE_NEGOTIATION_BITMASK_GUID_BYTES,
                    0,
                    guidBytes,
                    0,
                    RpceUtility.GUID_SIZE);
                guidBytes[RpceUtility.BIND_TIME_FEATURE_NEGOTIATION_BITMASK_PREFIX_LENGTH]
                    = (byte)bindTimeFeatureNegotiationBitmask.Value;
                p_cont_elem.transfer_syntaxes[0].if_uuid = new Guid(guidBytes);
                p_cont_elem.transfer_syntaxes[0].if_vers_major = 1;
                p_cont_elem.transfer_syntaxes[0].if_vers_minor = 0;
                p_cont_elem_list.Add(p_cont_elem);
            }
            bindPdu.p_context_elem.n_context_elem = (byte)p_cont_elem_list.Count;
            bindPdu.p_context_elem.reserved = 0;
            bindPdu.p_context_elem.reserved2 = 0;
            bindPdu.p_context_elem.p_cont_elem = p_cont_elem_list.ToArray();

            bindPdu.AppendAuthenticationVerifier();
            bindPdu.SetLength();

            return bindPdu;
        }