/// <summary> /// Open and immediately close a salesforce connection using the credential. If a failure occurs /// an exception is thrown. /// </summary> /// <param name="credential">The credential to test with.</param> /// <param name="configuration">Configuration for the connections.</param> public static void TestLogin(SalesForceCredential credential, Configuration configuration) { if (credential == null) { throw new ArgumentNullException("credential"); } if (configuration == null) { configuration = GetDefaultConfiguration(); } SalesForceAPI.Partner.Soap client = null; SalesForceSession session = new SalesForceSession(credential, configuration); try { client = session.CreatePartnerClient(); client.logout(new SalesForceAPI.Partner.logoutRequest( new SalesForceAPI.Partner.SessionHeader() { sessionId = session.Id }, null)); session.DisposeClient(client); } finally { if (client != null) { session.DisposeClient(client); } } }
/// <summary> /// Initialize all of the clients. /// </summary> private void InitClients() { if (_partnerClient == null) { _partnerClient = _session.CreatePartnerClient(); _metadataClient = _session.CreateMetadataClient(); _apexClient = _session.CreateApexClient(); _toolingClient = _session.CreateToolingClient(); } }
/// <summary> /// Login to SalesForce. /// </summary> private void Login() { SalesForceAPI.Partner.Soap loginClient = PartnerClientFactory.CreateChannel(); SalesForceAPI.Partner.loginResponse response = loginClient.login(new SalesForceAPI.Partner.loginRequest( null, null, _credential.Username, _credential.Password + _credential.Token)); _session = response.result; DisposeClient(loginClient); PartnerClientFactory.Endpoint.Address = new System.ServiceModel.EndpointAddress(_session.serverUrl); MetadataClientFactory.Endpoint.Address = new System.ServiceModel.EndpointAddress(_session.metadataServerUrl); ApexClientFactory.Endpoint.Address = new System.ServiceModel.EndpointAddress(_session.serverUrl.Replace("/u/", "/s/")); ToolingClientFactory.Endpoint.Address = new System.ServiceModel.EndpointAddress(_session.serverUrl.Replace("/u/", "/T/")); RestBaseUrl = String.Format("https://{0}/services/data/v{1:N1}", new Uri(_session.serverUrl).Host, SalesForceClient.METADATA_VERSION); User = new User(_session.userId, _session.userInfo.userFullName); UserEmail = _session.userInfo.userEmail; }