The client must obtain a SAML token from a
vCenter Single Sign-On Server. See the
vCenter Single Sign-On Programming
Guide. This code fragment performs the following actions:
Procedure
-
Calls the
LoginByTokenSample class
method
GetSecurityPolicyAssertionForHokToken (see
Security Policies in a C# Web Services SDK Client)
and adds the security policy to the
VimService object.
The
VimService object contains
the following data:
- vCenter Server URL.
- SAML token (stored in the security policy
assertion).
- X509 certificate (stored in the security
policy assertion).
-
Calls the
RetrieveServiceContent
method. The method establishes the connection with the vCenter Server and
provides access to the
SessionManager managed
object.
-
Calls the
LoginByToken method.
The .NET framework uses the security policy assertion to construct the login
request. The response includes a session cookie.
-
Calls the
LoginByTokenSample class
method
resetService to create a new
VimService object. The
session cookie is stored in the cookie container in the
VimService object.
Example: Connection and
Login
// Construct the security policy assertion
SecurityPolicyAssertion securityPolicyAssertion = null;
securityPolicyAssertion = GetSecurityPolicyAssertionForHokToken(xmlToken);
// Setting up the security policy for the request
Policy policySAML = new Policy();
policySAML.Assertions.Add(securityPolicyAssertion);
// Setting policy of the service
_service.SetPolicy(policySAML);
_sic = _service.RetrieveServiceContent(_svcRef);
if (_sic.sessionManager != null)
{
_service.LoginByToken(_sic.sessionManager, null);
}
resetService();