+ Start a Discussion
LBSLBS 

Cannot Set LoginResult.serverUrl - UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

Hi There,

I've been successfully using integrations to the SFDC using c# solution. So far I added the web reference and used it without any issues. But then I started add the Service Refference, by downloading the enteprise wsdl to local and used by Add Service Reference option. And I was reffering to following article (https://developer.salesforce.com/docs/atlas.en-us.salesforce_developer_environment_dotnet_tipsheet.meta/salesforce_developer_environment_dotnet_tipsheet/salesforce_developer_environment_verify_dotnet_wsdl.htm).
I was able to run the login function, but there I was unable set the serverUrl as I was unable to find the Url property on my SoalpClient. I think Becaues of that when it tries to SOQL query, it retuns following Error message. 
"UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService"

So when I was using web reference I was successfully able to create the sforcebinding and set the ServerUrl to the property I have in sforcebinding. Really Appriciate Your Help Here

Here is my code,

using SFServices.SFDC_FSb_9_23;

namespace SFServices
{
    class SFServiceClient
    {               
        private static SoapClient SFDC_FSb_9_23Binding;
        private static LoginResult CurrentLoginResult;   

        private bool SFLogin()
        {
            SFDC_FSb_9_23Binding = new SoapClient();  
            
            string UserName = "usename@domain.com.fsandbox";
            string Password = "passwordwithtoken";        
            
            try
            {
                CurrentLoginResult = SFDC_FSb_9_23Binding.login(null, UserName, Password);   
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw new Exception("Login Error: Please contact Technical Team for more details - "+ex);
                //return false;
            }
            if (CurrentLoginResult.passwordExpired)
            {
                throw new Exception("Password Expired: Please contact Technical Team for more details");
                //return false;
            }
            else
            {    

                //HOW CAN I SET THE ServerUrl. AND I THINK THE ISSUE IS HERE

                return true;                
            }
        }

-------------------------------------------------------------------------------------------------------------------------------------------
public bool sampleMethod(string field)
        {
            try
            {           
                if (SFLogin())
                {                    
                    String Query_1 = "SELECT Name, Id, FROM ACCOUNT WHERE custom_field__c='" + field + "'";
                    QueryResult qr = new QueryResult();                    
                    SFDC_FSb_9_23Binding.query(null, null, null, null, Query_1, out qr); // ISSUE COMES FROM HERE
                }
            }
        }  

Thanks,
Mudi
 
Daniel BallingerDaniel Ballinger
You will need to create an EndpointAddress from the servierUrl and use it to replace the SoapClient instance. E.g.
 
System.ServiceModel.EndpointAddress apiAddress = new System.ServiceModel.EndpointAddress(CurrentLoginResult.serverUrl);

SFDC_Fsb_9_23Binding = new SoapClient(SoapClient.EndpointConfiguration.Soap, apiAddress);

SFDC_Fsb_9_23Binding.query(...);