Пример #1
0
        private static IEnumerable <RpcEndpoint> QueryEndpoints(string search_binding, RpcEndpointInquiryFlag inquiry_flag, RPC_IF_ID if_id_search, RpcEndPointVersionOption version, UUID uuid_search, bool throw_on_error = true)
        {
            using (SafeRpcBindingHandle search_handle = string.IsNullOrEmpty(search_binding) ? SafeRpcBindingHandle.Null : SafeRpcBindingHandle.Create(search_binding))
            {
                int status = Win32NativeMethods.RpcMgmtEpEltInqBegin(search_handle,
                                                                     inquiry_flag,
                                                                     if_id_search, version, uuid_search, out SafeRpcInquiryHandle inquiry);
                if (status != 0)
                {
                    if (throw_on_error)
                    {
                        throw new SafeWin32Exception(status);
                    }
                    yield break;
                }

                using (inquiry)
                {
                    while (true)
                    {
                        RPC_IF_ID if_id = new RPC_IF_ID();
                        UUID      uuid  = new UUID();
                        status = Win32NativeMethods.RpcMgmtEpEltInqNext(inquiry, if_id, out SafeRpcBindingHandle binding, uuid, out SafeRpcStringHandle annotation);
                        if (status != 0)
                        {
                            if (status != 1772 && throw_on_error)
                            {
                                throw new SafeWin32Exception(status);
                            }
                            break;
                        }
                        try
                        {
                            yield return(new RpcEndpoint(if_id, uuid, annotation, binding, true));
                        }
                        finally
                        {
                            binding.Dispose();
                            annotation.Dispose();
                        }
                    }
                }
            }
        }
Пример #2
0
        private static IEnumerable <RpcEndpoint> QueryEndpoints(SafeRpcBindingHandle search_binding, RpcEndpointInquiryFlag inquiry_flag, RPC_IF_ID if_id_search, RpcEndPointVersionOption version, UUID uuid_search)
        {
            using (search_binding)
            {
                int status = Win32NativeMethods.RpcMgmtEpEltInqBegin(search_binding,
                                                                     inquiry_flag,
                                                                     if_id_search, version, uuid_search, out SafeRpcInquiryHandle inquiry);
                if (status != 0)
                {
                    throw new SafeWin32Exception(status);
                }

                using (inquiry)
                {
                    while (true)
                    {
                        RPC_IF_ID if_id = new RPC_IF_ID();
                        UUID      uuid  = new UUID();
                        status = Win32NativeMethods.RpcMgmtEpEltInqNext(inquiry, if_id, out SafeRpcBindingHandle binding, uuid, out SafeRpcStringHandle annotation);
                        if (status != 0)
                        {
                            if (status == 1772)
                            {
                                break;
                            }
                            throw new SafeWin32Exception(status);
                        }
                        try
                        {
                            yield return(new RpcEndpoint(if_id, uuid, annotation, binding));
                        }
                        finally
                        {
                            binding.Dispose();
                            annotation.Dispose();
                        }
                    }
                }
            }
        }