/ Published in: C#
"Log in" to Salesforce via this code. Borrowed heavily from URL reference.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private static SforceService Login() { // this is the web reference object generated by Visual Studio // Need to append password and security token together since we're logging in through the // Salesforce API string passwordPlusSecurityToken = string.Format("{0}{1}","password","token"); LoginResult loginResult; try { loginResult = service.login("salesforceUsername", passwordPlusSecurityToken); } catch (SoapException ex) { // Log error return null; } /** * Once the client application has logged in successfully, it will use * the results of the login call to reset the endpoint of the service * to the virtual server instance that is servicing your organization */ service.Url = loginResult.serverUrl; /** * The client application now has an instance of the SforceService * that is pointing to the correct endpoint. Next, the sample client * application sets a persistent SOAP header (to be included on all * subsequent calls that are made with SforceService) that contains the * valid sessionId for our login credentials. To do this, the * client application creates a new SessionHeader object and persists it to * the SforceService. Add the session ID returned from the login to the * session header. */ service.SessionHeaderValue.sessionId = loginResult.sessionId; return service; }
URL: http://wiki.developerforce.com/index.php/Integrating_Force.com_with_Microsoft_.NET