예제 #1
0
        public string Login(string token, string partnerUrl, string metaUrl, string InstanceDesc)
        {
            _instancedesc = InstanceDesc;

            // Create a service object
            _binding = new SforceService();

            // Timeout after a minute
            _binding.Timeout = 60000;

            // get the version from the default url
            int i1 = this._binding.Url.LastIndexOf('/') + 1;
            string version = this._binding.Url.Substring(i1);

            this._binding.Url = partnerUrl.Replace("/c/", "/u/");
            this._metaurl = metaUrl;

            // remember who we are
            this._binding.SessionHeaderValue = new sfPartner.SessionHeader();
            this._binding.SessionHeaderValue.sessionId = token;
            this._loggedin = true;

            // Setup and Get the url for the Ribbon web service binding
            _ribbonBinding = new Axiom_RibbonControllerService();
            _ribbonBinding.SessionHeaderValue = new sfRibbon.SessionHeader();
            _ribbonBinding.SessionHeaderValue.sessionId = token;
            int idx1 = this._binding.Url.IndexOf(@"/services/");
            int idx2 = _ribbonBinding.Url.IndexOf(@"/services/");
            if (idx1 == 0 || idx2 == 0)
            {
                return "problem with the urls";
            }
            _ribbonBinding.Url = this._binding.Url.Substring(0, idx1) + _ribbonBinding.Url.Substring(idx2);

            // check we are logged in
            string ok = "";
            try
            {
                this._userid = _binding.getUserInfo().userId;
                this._loggedin = true;
                ok = "";
            }
            catch (Exception e)
            {
                this._loggedin = false;
                ok = e.Message;
            }

            return ok;
        }
예제 #2
0
        public string Login(string Username,string Password,string Token,string Url,string InstanceDesc)
        {
            _instancedesc = InstanceDesc;

            // Create a service object
            _binding = new SforceService();

            // Timeout after a minute
            _binding.Timeout = 60000;

            // to get Fiddler (http://www.telerik.com/fiddler) to work - this can be helpful when trying to dubug Soap API issues
            //
            // System.Net.WebProxy wp = new System.Net.WebProxy("http://127.0.0.1:8888", false);
            // _binding.Proxy = wp;

            // don't relly on the default binding url cause we want to set the API version
            if (Url == "") Url = "https://login.salesforce.com";

            try
            {
                if (Url != "")
                {
                    //if its just the web site address and not the soap endpoint add that in
                    if (!Url.Contains("services/Soap/"))
                    {
                        // don't use the default API version - use the defined one
                        LocalSettings l = Globals.ThisAddIn.GetLocalSettings();
                        Url += "/services/Soap/u/" + l.SoapVersion + "/";
                    }
                    _binding.Url = Url;
                }
            } catch (Exception e)
            {
                return "Problem with the URL: " + e.Message;
            }

            // Try logging in
            LoginResult lr;
            try
            {
                lr = _binding.login(Username.Trim(), Password.Trim() + Token.Trim());
            }
            catch (SoapException e)
            {
                return e.Code + " " + e.Message;
            }
            catch (Exception e)
            {
                return e.Message;
            }

            // Check if the password has expired
            if (lr.passwordExpired)
            {
                return "Password has expired - please login to Salesforce and update";
            }

            String authEndPoint = _binding.Url;
            _binding.Url = lr.serverUrl;

            Uri sforceurl = new Uri(lr.serverUrl);
            _url = sforceurl.Scheme + "://" + sforceurl.Host;

            //remember the meta end point may need later
            _metaurl = lr.metadataServerUrl;

            //remember who we are
            _binding.SessionHeaderValue = new sfPartner.SessionHeader();
            _binding.SessionHeaderValue.sessionId = lr.sessionId;

            _loggedin = true;
            _userid = lr.userId;

            // Get the url for the Ribbon web service binding
            _ribbonBinding = new Axiom_RibbonControllerService();
            _ribbonBinding.SessionHeaderValue = new sfRibbon.SessionHeader();
            _ribbonBinding.SessionHeaderValue.sessionId = lr.sessionId;

            int idx1 = lr.serverUrl.IndexOf(@"/services/");
            int idx2 = _ribbonBinding.Url.IndexOf(@"/services/");
            if (idx1 == 0 || idx2 == 0)
            {
                return "Pproblem with the urls";
            }
            _ribbonBinding.Url = lr.serverUrl.Substring(0, idx1) + _ribbonBinding.Url.Substring(idx2);

            return "";
        }