public static extern uint RpcBindingSetAuthInfo( IntPtr Binding, string ServerPrincName, RPC_C_AUTHN_LEVEL AuthnLevel, RPC_C_AUTHN AuthnSvc, ref SEC_WINNT_AUTH_IDENTITY AuthIdentity, RPC_C_AUTHN AuthzService);
/// <summary> /// Use the input parameter of rpcClientConfig to bind a RPC handle and set its authentication and /// authorization information. /// The caller is responded for calling Unbind to free the output handle. /// The following default values will be used when PInvoke RPC binding API: /// RpcStringBindingCompose: ObjUuid is set to null, Options is set to null. /// </summary> /// <param name="rpcClientConfig">Contains the parameters used by WinAPI for RPC binding.</param> /// <returns>the RPC binding handle.</returns> /// <exception cref="System.InvalidOperationException">Fail to PInvoke.</exception> public static IntPtr Bind(RpcClientConfig rpcClientConfig) { IntPtr bindingHandle = IntPtr.Zero; IntPtr bindingString = IntPtr.Zero; uint status = RpcNativeMethods.RpcStringBindingCompose( (rpcClientConfig.ClientGuid == null) ? null : rpcClientConfig.ClientGuid.Value.ToString(), rpcClientConfig.ProtocolSequence, rpcClientConfig.ServerComputerName, rpcClientConfig.EndPoint, rpcClientConfig.NetworkOptions, out bindingString); if (status != 0) { throw new InvalidOperationException("Failed to RpcStringBindingCompose. The returned status is " + status); } status = RpcNativeMethods.RpcBindingFromStringBinding( bindingString, out bindingHandle); if (status != 0) { throw new InvalidOperationException("Failed to RpcBindingFromStringBinding. The returned status is " + status); } status = RpcNativeMethods.RpcStringFree( ref bindingString); if (status != 0) { throw new InvalidOperationException("Failed to RpcStringFree. The returned status is " + status); } SEC_WINNT_AUTH_IDENTITY authenticationIdentity = rpcClientConfig.AuthenticationIdentity; status = RpcNativeMethods.RpcBindingSetAuthInfo( bindingHandle, rpcClientConfig.ServicePrincipalName, rpcClientConfig.AuthenticationLevel, rpcClientConfig.AuthenticationService, ref authenticationIdentity, rpcClientConfig.AuthorizationService); if (status != 0) { throw new InvalidOperationException("Failed to RpcBindingSetAuthInfo. The returned status is " + status); } return(bindingHandle); }
/// <summary> /// Constructor /// </summary> /// <param name="clientGuid">an object UUID which represents the RPC caller.</param> /// <param name="serverComputerName">the NetworkingAddress of the RPC server.</param> /// <param name="protocolSequence">a string representation of a protocol sequence.</param> /// <param name="endPoint">a string representation of an endpoint.</param> /// <param name="networkOptions">a string representation of network options. The option string is associated /// with the protocol sequence.</param> /// <param name="servicePrincipalName">the expected principal name of the server referenced by Binding.</param> /// <param name="authenticationLevel">Level of authentication to be performed on remote procedure calls /// made using Binding.</param> /// <param name="authenticationService">Authentication service to use.</param> /// <param name="authenticationIdentity">the structure containing the client's authentication and /// authorization credentials appropriate for the selected authentication and authorization service.</param> /// <param name="authorizationService">Authorization service implemented by the server for the interface of /// interest.</param> public RpcClientConfig( Guid? clientGuid, String serverComputerName, String protocolSequence, String endPoint, String networkOptions, String servicePrincipalName, RPC_C_AUTHN_LEVEL authenticationLevel, RPC_C_AUTHN authenticationService, SEC_WINNT_AUTH_IDENTITY authenticationIdentity, RPC_C_AUTHN authorizationService) { this.clientGuid = clientGuid; this.serverComputerName = serverComputerName; this.protocolSequence = protocolSequence; this.endPoint = endPoint; this.networkOptions = networkOptions; this.servicePrincipalName = servicePrincipalName; this.authenticationLevel = authenticationLevel; this.authenticationService = authenticationService; this.authenticationIdentity = authenticationIdentity; this.authorizationService = authorizationService; }
/// <summary> /// Constructor /// </summary> /// <param name="clientGuid">an object UUID which represents the RPC caller.</param> /// <param name="serverComputerName">the NetworkingAddress of the RPC server.</param> /// <param name="protocolSequence">a string representation of a protocol sequence.</param> /// <param name="endPoint">a string representation of an endpoint.</param> /// <param name="networkOptions">a string representation of network options. The option string is associated /// with the protocol sequence.</param> /// <param name="servicePrincipalName">the expected principal name of the server referenced by Binding.</param> /// <param name="authenticationLevel">Level of authentication to be performed on remote procedure calls /// made using Binding.</param> /// <param name="authenticationService">Authentication service to use.</param> /// <param name="authenticationIdentity">the structure containing the client's authentication and /// authorization credentials appropriate for the selected authentication and authorization service.</param> /// <param name="authorizationService">Authorization service implemented by the server for the interface of /// interest.</param> public RpcClientConfig( Guid?clientGuid, String serverComputerName, String protocolSequence, String endPoint, String networkOptions, String servicePrincipalName, RPC_C_AUTHN_LEVEL authenticationLevel, RPC_C_AUTHN authenticationService, SEC_WINNT_AUTH_IDENTITY authenticationIdentity, RPC_C_AUTHN authorizationService) { this.clientGuid = clientGuid; this.serverComputerName = serverComputerName; this.protocolSequence = protocolSequence; this.endPoint = endPoint; this.networkOptions = networkOptions; this.servicePrincipalName = servicePrincipalName; this.authenticationLevel = authenticationLevel; this.authenticationService = authenticationService; this.authenticationIdentity = authenticationIdentity; this.authorizationService = authorizationService; }