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
parthibanparthiban 

please help!! very urgent

 i am developing an integration application in .net with salesforce, users are allowded to choose objects and its corresponding fields at run time, after that how to code it dynamically using enterprise WSDL to insert the object by using C#.

Chris987654321Chris987654321

 

DataTable GetSforceData(string strSQL, int iBatchSize)
        {
            DataTable dt = null;
            
            SforceService binding = new SforceService();
            
           
            //get account name, account password and security token here            
            LoginResult lr = binding.login(strAccountName,strAccountPassword + strSecurityToken);

            if (!lr.passwordExpired)
            {
                binding.Url = lr.serverUrl;
                binding.SessionHeaderValue = new partnerWSDL.SessionHeader();
                binding.SessionHeaderValue.sessionId = lr.sessionId;

                partnerWSDL.QueryResult qr = null;
                binding.QueryOptionsValue = new partnerWSDL.QueryOptions();
                binding.QueryOptionsValue.batchSize = iBatchSize;
                binding.QueryOptionsValue.batchSizeSpecified = true;
                try
                {
                    qr = binding.query(strSQL);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "Error peforming query");
                    return null;
                }

                bool done = false;

                if (qr.size > 0)
                {
                    dt = new DataTable();
                    partnerWSDL.sObject sOtmp = (partnerWSDL.sObject)qr.records[0];
                    
                    for (int i = 0; i < sOtmp.Any.Length; i++)
                    {
                        dt.Columns.Add(sOtmp.Any[i].LocalName);
                    }
                    string[] prValues = new string[sOtmp.Any.Length];
                    while (!done)
                    {
                        for (int i = 0; i < qr.records.Length; i++)
                        {
                            sOtmp = (partnerWSDL.sObject)qr.records[i];
                            for (int j = 0; j < sOtmp.Any.Length; j++)
                            {
                                if (sOtmp.Any[j].ChildNodes.Count > 1)
                                {
                                    prValues.SetValue(sOtmp.Any[j].ChildNodes[2].InnerText, j);
                                }
                                else
                                {
                                    prValues.SetValue(sOtmp.Any[j].InnerText, j);
                                }
                            }

                            dt.Rows.Add(prValues);
                        }

                        if (qr.done)
                        {
                            done = true;
                        }
                        else
                        {
                            qr = binding.queryMore(qr.queryLocator);
                        }
                    }
                }
            }

            return dt;
             
        }

 That code could get you started. It takes a query and returns the results in a datatable

 

Chris987654321Chris987654321

You could also look at the source for Data Loader but it's written in Java

Darren TerrellDarren Terrell

My Salesforce Integration with .Net - Web Services SOAP API article will show you how to interact with the enterprise.wsdl in .Net to do all of the necessary CRUD work.  It has a nice wrapper for working with SF connections and such.  If you still run into problems, then let me know what you're running into and I'll see if I can help.

 

http://www.developer.com/net/net/salesforce-integration-with-.net-web-services-soap-api-.html