public static int Main(string[] args) { string pszUuid = null; var pszProtocolSequence = "ncacn_ip_tcp"; string pszNetworkAddress = null; var pszEndpoint = "8765"; string pszSpn = null; string pszOptions = null; var pszString = "hello, world"; uint ulCode; int i; // allow the user to override settings with command line switches for (i = 0; i < args.Length; i++) { if ((args[i][0] == '-') || (args[i][0] == '/')) { switch (char.ToLower(args[i][1])) { case 'p': // protocol sequence pszProtocolSequence = args[++i]; break; case 'n': // network address pszNetworkAddress = args[++i]; break; case 'e': // endpoint pszEndpoint = args[++i]; break; case 'a': pszSpn = args[++i]; break; case 'o': pszOptions = args[++i]; break; case 's': pszString = args[++i]; break; case 'h': case '?': default: return(Usage()); } } else { return(Usage()); } } // Use a convenience function to concatenate the elements of the string binding into the proper sequence. Win32Error status = RpcStringBindingCompose(pszUuid, pszProtocolSequence, pszNetworkAddress, pszEndpoint, pszOptions, out var pszStringBinding); Console.Write("RpcStringBindingCompose returned {0}\n", status); Console.Write("pszStringBinding = {0}\n", pszStringBinding); if (status.Failed) { exit(status); } // Set the binding handle that will be used to bind to the server. status = RpcBindingFromStringBinding(pszStringBinding, out SafeRPC_BINDING_HANDLE hello_IfHandle); Console.Write("RpcBindingFromStringBinding returned {0}\n", status); if (status.Failed) { exit(status); } using (hello_IfHandle) { // User did not specify spn, construct one. pszSpn ??= Spn.Make(); // Set the quality of service on the binding handle var SecQos = new RPC_SECURITY_QOS { Version = RPC_C_SECURITY_QOS_VERSION, Capabilities = RPC_C_QOS_CAPABILITIES.RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH, IdentityTracking = RPC_C_QOS_IDENTITY.RPC_C_QOS_IDENTITY_DYNAMIC, ImpersonationType = RPC_C_IMP_LEVEL.RPC_C_IMP_LEVEL_IDENTIFY }; // Set the security provider on binding handle status = RpcBindingSetAuthInfoEx(hello_IfHandle, pszSpn, RPC_C_AUTHN_LEVEL.RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_AUTHN.RPC_C_AUTHN_GSS_NEGOTIATE,
public static int Main(string[] args) { string pszProtocolSequence = "ncacn_ip_tcp"; IntPtr pszSecurity = default; string pszEndpoint = "8765"; string pszSpn = default; uint cMinCalls = 1; uint cMaxCalls = 20; bool fDontWait = false; int i; // allow the user to override settings with command line switches for (i = 0; i < args.Length; i++) { if ((args[i][0] == '-') || (args[i][0] == '/')) { switch (char.ToLower(args[i][1])) { case 'p': // protocol sequence pszProtocolSequence = args[++i]; break; case 'e': pszEndpoint = args[++i]; break; case 'a': pszSpn = args[++i]; break; case 'm': cMaxCalls = uint.Parse(args[++i]); break; case 'n': cMinCalls = uint.Parse(args[++i]); break; case 'f': fDontWait = bool.Parse(args[++i]); break; case 'h': case '?': default: return(Usage()); } } else { return(Usage()); } } var status = RpcServerUseProtseqEp(pszProtocolSequence, cMaxCalls, pszEndpoint, pszSecurity); // Security descriptor Console.Write("RpcServerUseProtseqEp returned {0}\n", status); if (status.Failed) { exit(status); } // User did not specify spn, construct one. pszSpn ??= Spn.Make(); // Using Negotiate as security provider. status = RpcServerRegisterAuthInfo(pszSpn, RPC_C_AUTHN.RPC_C_AUTHN_GSS_NEGOTIATE); Console.Write("RpcServerRegisterAuthInfo returned {0}\n", status); if (status.Failed) { exit(status); } status = RpcServerRegisterIfEx(hello_ServerIfHandle, default, default, 0, RPC_C_LISTEN_MAX_CALLS_DEFAULT, default);