0

At the moment I'm merely trying to achieve authentication and some very basic things, but I keep stumbling upon the same exception.

I have inserted both the CallOptions and the LoginScopeHeader as nulls to the login (line 55) since it's what I've seen people do in the docs. I also went to see the docs and I saw that those two parameters don't really provide me with any value since they're for org namespace, portalId, etc. Nonetheless, that's where the exception is thrown.

On the one hand, I have thought that I might be configuring headers wrong, since I'm not really specifying any url or anything, but on the other I thought that that's specified in the specific WSDL, right?

As you will see the code is as is in the documentation, except a couple of calls that required more parameters.

In any case, any help is appreciated! Thanks :=)

Exception

{"There was an error in serializing one of the headers in message loginRequest: 'Unable to generate a temporary class (result=1).\r\nerror CS0030: Cannot convert type 'ForceConsole.PartnerSOAP.ListViewRecordColumn[]' to 'ForceConsole.PartnerSOAP.ListViewRecordColumn'\r\nerror CS0030: Cannot convert type 'ForceConsole.PartnerSOAP.ListViewRecordColumn[]' to 'ForceConsole.PartnerSOAP.ListViewRecordColumn'\r\nerror CS0029: Cannot implicitly convert type 'ForceConsole.PartnerSOAP.ListViewRecordColumn' to 'ForceConsole.PartnerSOAP.ListViewRecordColumn[]'\r\nerror CS0029: Cannot implicitly convert type 'ForceConsole.PartnerSOAP.ListViewRecordColumn' to 'ForceConsole.PartnerSOAP.ListViewRecordColumn[]'\r\n'.  Please see InnerException for more details."}

Code

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);
            }
        }
    }
}
1

I've run into the "Cannot convert type 'X.Y.ListViewRecordColumn[]' to 'X.Y.ListViewRecordColumn'" error previously. This started happening in Winter '15 (v32.0) when the ListViewRecord complex type started including an unbound collection of ListViewRecordColumn records.

The problem will be the XmlArrayItemAttribute that is associated with the records property in the C# class that is generated from the WSDL.

You need to change it from:

[System.Xml.Serialization.XmlArrayItemAttribute("columns", typeof(ListViewRecordColumn), IsNullable=false)]

to:

[System.Xml.Serialization.XmlArrayItemAttribute("columns", typeof(ListViewRecordColumn[]), IsNullable=false)]

Note the additional [] in appended to the typeof statement.

See also:

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.