/// <summary> /// Resolve the binding string for this service from the the Endpoint Mapper. /// </summary> /// <param name="protocol_seq">The protocol sequence to lookup.</param> /// <param name="network_address">The network address to lookup the endpoint.</param> /// <param name="interface_id">Interface UUID to lookup.</param> /// <param name="interface_version">Interface version lookup.</param> /// <remarks>This only will return a valid value if the service is running and registered with the Endpoint Mapper. It can also hang.</remarks> /// <returns>The RPC binding string. Empty string if it doesn't exist or the lookup failed.</returns> public static string MapServerToBindingString(string protocol_seq, string network_address, Guid interface_id, Version interface_version) { using (var binding = SafeRpcBindingHandle.Create(null, protocol_seq, network_address, null, null, false)) { return(MapBindingToBindingString(binding, interface_id, interface_version)); } }
/// <summary> /// Resolve the binding string for this service from the Endpoint Mapper. /// </summary> /// <param name="string_binding">The binding string to map.</param> /// <param name="interface_id">Interface UUID to lookup.</param> /// <param name="interface_version">Interface version lookup.</param> /// <remarks>This only will return a valid value if the service is running and registered with the Endpoint Mapper. It can also hang.</remarks> /// <returns>The RPC binding string. Empty string if it doesn't exist or the lookup failed.</returns> public static string MapBindingToBindingString(string string_binding, Guid interface_id, Version interface_version) { using (var binding = SafeRpcBindingHandle.Create(string_binding, false)) { return(MapBindingToBindingString(binding, interface_id, interface_version)); } }
/// <summary> /// Query for endpoints for a RPC binding. /// </summary> /// <param name="alpc_port">The ALPC port to query. Can be a full path as long as it contains \RPC Control\ somewhere.</param> /// <returns>The list of endpoints on the RPC binding.</returns> public static IEnumerable <RpcEndpoint> QueryEndpointsForAlpcPort(string alpc_port) { int index = alpc_port.IndexOf(@"\RPC Control\", StringComparison.OrdinalIgnoreCase); if (index >= 0) { alpc_port = alpc_port.Substring(0, index) + RPC_CONTROL_PATH + alpc_port.Substring(index + RPC_CONTROL_PATH.Length); } return(QueryEndpointsForBinding(SafeRpcBindingHandle.Create(null, "ncalrpc", null, alpc_port, null))); }
/// <summary> /// Resolve the binding string for this service from the the Endpoint Mapper. /// </summary> /// <param name="protocol_seq">The protocol sequence to lookup.</param> /// <param name="network_address">The network address to lookup the endpoint.</param> /// <param name="interface_id">Interface UUID to lookup.</param> /// <param name="interface_version">Interface version lookup.</param> /// <remarks>This only will return a valid value if the service is running and registered with the Endpoint Mapper. It can also hang.</remarks> /// <returns>The RPC binding string. Empty string if it doesn't exist or the lookup failed.</returns> public static string MapServerToBindingString(string protocol_seq, string network_address, Guid interface_id, Version interface_version) { using (var binding = SafeRpcBindingHandle.Create(null, protocol_seq, network_address, null, null, false)) { if (!binding.IsSuccess) { return(string.Empty); } RPC_SERVER_INTERFACE ifspec = new RPC_SERVER_INTERFACE(); ifspec.Length = Marshal.SizeOf(ifspec); ifspec.InterfaceId.SyntaxGUID = interface_id; ifspec.InterfaceId.SyntaxVersion = interface_version.ToRpcVersion(); var result = Win32NativeMethods.RpcEpResolveBinding(binding.Result, ref ifspec); if (result != Win32Error.SUCCESS) { return(string.Empty); } return(binding.Result.ToString()); } }
/// <summary> /// Query for endpoints for a RPC binding. /// </summary> /// <param name="string_binding">The RPC binding to query, e.g. ncalrpc:[PORT]</param> /// <returns>The list of endpoints on the RPC binding.</returns> public static IEnumerable <RpcEndpoint> QueryEndpointsForBinding(string string_binding) { return(QueryEndpointsForBinding(SafeRpcBindingHandle.Create(string_binding))); }
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(); } } } } }