Exemplo n.º 1
0
        public DrsrClientSessionContext BindOverTcp(
            string serverName,
            ClientSecurityContext securityContext,
            RpceAuthenticationLevel authenticationLevel,
            TimeSpan timeout)
        {
            DrsrClientSessionContext clientSessionContext = new DrsrClientSessionContext();

            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }

            this.rpcAdapter.Bind(
                RpceUtility.RPC_OVER_TCPIP_PROTOCOL_SEQUENCE,
                serverName,
                DrsrUtility.QueryDrsrTcpEndpoint(DrsrRpcInterfaceType.DSAOP, serverName)[0].ToString(),
                securityContext,
                authenticationLevel,
                timeout);

            clientSessionContext.RPCHandle = rpcAdapter.Handle;

            return(clientSessionContext);
        }
Exemplo n.º 2
0
        public T ExpectRpcCall <T>(
            DrsrRpcInterfaceType interfaceType,
            TimeSpan timeout,
            out DrsrServerSessionContext sessionContext)
            where T : DrsrRequestStub
        {
            RpceServerSessionContext rpceSessionContext;
            ushort opnum;

            byte[] requestStub = rpceLayerServer.ExpectCall(timeout, out rpceSessionContext, out opnum);

            if ((interfaceType == DrsrRpcInterfaceType.DSAOP &&
                 !Enum.IsDefined(typeof(DsaopMethodOpnums), (ushort)opnum)) ||
                (interfaceType == DrsrRpcInterfaceType.DRSUAPI &&
                 !Enum.IsDefined(typeof(DrsuapiMethodOpnums), (ushort)opnum)))
            {
                throw new InvalidOperationException("An invalid method is invoked");
            }

            //If there isn't a corresponding Drsr session context, it's a new session
            if (contextManager.LookupSessionContext(rpceSessionContext, out sessionContext))
            {
                sessionContext.RpceLayerSessionContext = rpceSessionContext;
            }

            T t;

            if (typeof(T) == typeof(DrsrRequestStub))
            {
                t = (T)DrsrUtility.CreateDrsrRequestStub(interfaceType, opnum);
            }
            else
            {
                t = (T)Activator.CreateInstance(typeof(T));
                if ((ushort)t.Opnum != opnum)
                {
                    throw new InvalidOperationException("An unexpected method call is received");
                }
            }

            //Decode the request stub
            t.Decode(sessionContext, requestStub);

            //Update the session context
            sessionContext.UpdateSessionContextWithMessageReceived(interfaceType, t);
            return(t);
        }