Opc.Ua.Com.ComUtils.ServerInfo.Allocate C# (CSharp) Method

Allocate() public method

Allocates a COSERVERINFO structure.
public Allocate ( string hostName, UserIdentity identity ) : COSERVERINFO
hostName string
identity UserIdentity
return COSERVERINFO
			public COSERVERINFO Allocate(string hostName, UserIdentity identity)
			{
				// initialize server info structure.
				COSERVERINFO serverInfo = new COSERVERINFO();

				serverInfo.pwszName     = hostName;
				serverInfo.pAuthInfo    = IntPtr.Zero;
				serverInfo.dwReserved1  = 0;
				serverInfo.dwReserved2  = 0;
                
                // no authentication for default identity
				if (UserIdentity.IsDefault(identity))
                {
					return serverInfo;
                }

				m_hUserName  = GCHandle.Alloc(identity.Username, GCHandleType.Pinned);
				m_hPassword  = GCHandle.Alloc(identity.Password, GCHandleType.Pinned);
				m_hDomain    = GCHandle.Alloc(identity.Domain,   GCHandleType.Pinned);

				m_hIdentity = new GCHandle();

				// create identity structure.
				COAUTHIDENTITY authIdentity = new COAUTHIDENTITY();

				authIdentity.User           = m_hUserName.AddrOfPinnedObject();
				authIdentity.UserLength     = (uint)((identity.Username != null)?identity.Username.Length:0);
				authIdentity.Password       = m_hPassword.AddrOfPinnedObject();
				authIdentity.PasswordLength = (uint)((identity.Password != null)?identity.Password.Length:0);
				authIdentity.Domain         = m_hDomain.AddrOfPinnedObject();
				authIdentity.DomainLength   = (uint)((identity.Domain != null)?identity.Domain.Length:0);
				authIdentity.Flags          = SEC_WINNT_AUTH_IDENTITY_UNICODE;

				m_hIdentity = GCHandle.Alloc(authIdentity, GCHandleType.Pinned);
					
				// create authorization info structure.
				COAUTHINFO authInfo = new COAUTHINFO();

				authInfo.dwAuthnSvc           = RPC_C_AUTHN_WINNT;
				authInfo.dwAuthzSvc           = RPC_C_AUTHZ_NONE;
				authInfo.pwszServerPrincName  = IntPtr.Zero;
				authInfo.dwAuthnLevel         = RPC_C_AUTHN_LEVEL_CONNECT;
				authInfo.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
				authInfo.pAuthIdentityData    = m_hIdentity.AddrOfPinnedObject();
                authInfo.dwCapabilities       = EOAC_NONE; // EOAC_DYNAMIC_CLOAKING;

				m_hAuthInfo = GCHandle.Alloc(authInfo, GCHandleType.Pinned);
			
				// update server info structure.
				serverInfo.pAuthInfo = m_hAuthInfo.AddrOfPinnedObject();

				return serverInfo;
			}
ComUtils.ServerInfo