Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"There was an error in serializing one of the headers in message loginRequest: 'Unable to generate a temporary class (result=1).rnerror CS0030: Cannot convert type 'ForceConsole.PartnerSOAP.ListViewRecordColumn[]' to 'ForceConsole.PartnerSOAP.ListViewRecordColumn'rnerror CS0030: Cannot convert type 'ForceConsole.PartnerSOAP.ListViewRecordColumn[]' to 'ForceConsole.PartnerSOAP.ListViewRecordColumn'rnerror CS0029: Cannot implicitly convert type 'ForceConsole.PartnerSOAP.ListViewRecordColumn' to 'ForceConsole.PartnerSOAP.ListViewRecordColumn[]'rnerror CS0029: Cannot implicitly convert type 'ForceConsole.PartnerSOAP.ListViewRecordColumn' to 'ForceConsole.PartnerSOAP.ListViewRecordColumn[]'rn'. Please see InnerException for more details."}
- namespace ForceConsole
- {
- using ForceConsole.PartnerSOAP;
- using System;
- using System.ServiceModel;
- class Program
- {
- private static SoapClient loginClient; // for login endpoint
- private static SoapClient client; // for API endpoint
- private static SessionHeader header;
- private static EndpointAddress endpoint;
- static void Main(string[] args)
- {
- Program sample = new Program();
- sample.run();
- }
- public void run()
- {
- // Make a login call
- if (login())
- {
- // Log out
- logout();
- }
- Console.ReadLine();
- }
- private bool login()
- {
- Console.Write("Enter username: ");
- string username = Console.ReadLine();
- Console.Write("Enter password: ");
- string password = Console.ReadLine();
- // Create a SoapClient specifically for logging in
- loginClient = new SoapClient();
- // (combine pw and token if necessary)
- LoginResult lr;
- try
- {
- Console.WriteLine("nLogging in...n");
- lr = loginClient.login(null, null, username, password); //TODO
- }
- catch (Exception e)
- {
- // Write the fault message to the console
- Console.WriteLine("An unexpected error has occurred: " + e.Message);
- // Write the stack trace to the console
- Console.WriteLine(e.StackTrace);
- return false;
- }
- // Check if the password has expired
- if (lr.passwordExpired)
- {
- Console.WriteLine("An error has occurred. Your password has expired.");
- return false;
- }
- /** 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
- */
- // On successful login, cache session info and API endpoint info
- endpoint = new EndpointAddress(lr.serverUrl);
- /** The sample client application now has a cached EndpointAddress
- * that is pointing to the correct endpoint. Next, the sample client
- * application sets a persistent SOAP header that contains the
- * valid sessionId for our login credentials. To do this, the sample
- * client application creates a new SessionHeader object. Add the session
- * ID returned from the login to the session header
- */
- header = new SessionHeader();
- header.sessionId = lr.sessionId;
- // Create and cache an API endpoint client
- client = new SoapClient("Soap", endpoint);
- printUserInfo(lr, lr.serverUrl);
- // Return true to indicate that we are logged in, pointed
- // at the right URL and have our security token in place.
- return true;
- }
- private void printUserInfo(LoginResult lr, String authEP)
- {
- try
- {
- GetUserInfoResult userInfo = lr.userInfo;
- Console.WriteLine("nLogging in ...n");
- Console.WriteLine("UserID: " + userInfo.userId);
- Console.WriteLine("User Full Name: " +
- userInfo.userFullName);
- Console.WriteLine("User Email: " +
- userInfo.userEmail);
- Console.WriteLine();
- Console.WriteLine("SessionID: " +
- lr.sessionId);
- Console.WriteLine("Auth End Point: " +
- authEP);
- Console.WriteLine("Service End Point: " +
- lr.serverUrl);
- Console.WriteLine();
- }
- catch (Exception e)
- {
- Console.WriteLine("An unexpected error has occurred: " + e.Message +
- " Stack trace: " + e.StackTrace);
- }
- }
- private void logout()
- {
- try
- {
- client.logout(header, null); //TODO
- Console.WriteLine("Logged out.");
- }
- catch (Exception e)
- {
- // Write the fault message to the console
- Console.WriteLine("An unexpected error has occurred: " + e.Message);
- // Write the stack trace to the console
- Console.WriteLine(e.StackTrace);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment