function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prashanth KamasamudramPrashanth Kamasamudram 

get metadata for all objects C# code

I am trying to get metadata for all objects using Partner API, 


got some samples in internet for calling binding .describeGlobal();


but when I am calling describeGlobal  its expecting   SessionHeader, CallOptions, PakageVersions[]


also there is no URL property for my binding object , and If I pass nulls for binding .describeGlobal(); instead of parameters, Giving following exception


UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService



Please somebody give me a code snippet to get Metada for all objects using partner API, I wanna use partner API because I want my code to work for any organization without any change.


After you use the login method to login to salesforce, you get back a LoginResult object. This object has a session ID and a destination URL.
The initial login request will be passed to a login server in salesforce, but future requests will have to be directed to your instance of salesforce. This instance URL is the destination URL.

Both of these (Session ID and Destination URL) must be set in the SforceService. This ensures all future queries hit the destination URL.

Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.
Prashanth KamasamudramPrashanth Kamasamudram

Hi ,


    I am using same steps,  but there is no option to set returned  URL . Please check my code and if there is any working code please suggest me...


public partial class Form1 : Form

//EnterpriseService.SoapClient loginClient;
private partner.SoapClient binding;
private partner.LoginResult lr;
//private SaveExpenditureWebServiceService myBinding = new SaveExpenditureWebServiceService();

public Form1()






private void button1_Click(object sender, EventArgs e)
//use default binding and address from app.config
//using (EnterpriseService.SoapClient loginClient = new EnterpriseService.SoapClient("Soap"))

using (partner.SoapClient binding = new partner.SoapClient("Soap"))
//set account password and account token variables
string sfdcPassword = "pwd$";
string sfdcToken = "Zpm2Mmdi5Ni0nQqRedERYX6tZ";
//set to user account that has API access enabled
string sfdcUserName = "";
//create login password value which combines password and token
string loginPassword = sfdcPassword + sfdcToken;
binding.ClientCredentials.UserName.UserName = sfdcUserName;
binding.ClientCredentials.UserName.Password = sfdcPassword;

//call Login operation from Enterprise WSDL
lr =
binding.login(null, null, //LoginScopeHeader
sfdcUserName, //username
loginPassword); //password

//get response values
string sessionId = lr.sessionId;
string serverUrl = lr.serverUrl;
//print response values
Console.WriteLine(string.Format("The session ID is {0} and server URL is {1}", sessionId, serverUrl));
Console.WriteLine("Press [Enter] to continue ...");
//binding = new partner.SoapClient("SoapBinding2");




private void describeGlobal()

partner.SessionHeader sheader = new partner.SessionHeader();
sheader.sessionId = lr.sessionId;
binding.Endpoint.ListenUri = new Uri(lr.metadataServerUrl);
describeGlobalRequest dgrq = new describeGlobalRequest(sheader, null, null);
//dgrq.SessionHeader = sheader;
partner.DescribeGlobalResult dgr = binding.describeGlobal(sheader, null, null);

//Loop through the array echoing the object names to the console
StringBuilder sb = new StringBuilder();
for (int i = 0; i < dgr.sobjects.Length; i++)
sb.Append(dgr.sobjects[i].name + " , ");



The Binding is going out of scope after you login. After you leave this code, the object is out of scope and it isn't the same one as your class level variable.

using (partner.SoapClient binding = new partner.SoapClient("Soap"))

Use only the class level varible:


binding = new partner.SoapClient("Soap");