wadewegner / Force.com-Toolkit-for-NET

The Force.com Toolkits for .NET provides an easy way for .NET developers to interact with the Force.com & Chatter REST APIs using native libraries.
BSD 3-Clause "New" or "Revised" License
374 stars 395 forks source link

Unable to retrieve data from salesforce #68

Closed c4less closed 10 years ago

c4less commented 10 years ago

I tried with the sample provided in the link

image

But i got a new exception msg

System.AggregateException was unhandled HResult=-2146233088 Message=One or more errors occurred. Source=mscorlib StackTrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result() at ConsoleApplication1.Program.Main(String[] args) in h:\ASP.net\SalesforceApplication\SalesforceApplication\Program.cs:line 33 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: Salesforce.Common.ForceException HResult=-2146233088 Message=API is not enabled for this Organization or Partner Source=Salesforce.Common StackTrace: at Salesforce.Common.ServiceHttpClient.d__1`1.MoveNext() InnerException:

Kindly provide some soln

wadewegner commented 10 years ago

@c4less, it would be a lot more helpful if you would share more details and post your code. Are you in a developer org or something else? Why are you doing this in a console app - is this really what you're trying to build?

c4less commented 10 years ago

@wadewegner I'm trying to do it in console app cos we are doing POC in our Project. Already i've implemented salesforce connectivity using Enterprise WSDL(SOAP). I've seen ur TechEd video regarding the Force.com SDK (Rest API). Once I succeeds i'm goin to build a WCF(Rest) Service to fetch the salesforce data

namespace ConsoleApplication1 { class Program { private static string _securityToken = "N3Ozbd9g7W3peTjLGyCftvBX"; private static string _clientId = "3MVG9Y6d_Btp4xp7IvhDe4vCNZJVNHEKCmcv4UFeXmFD2OdG52U.B6SkXLVUHB5Nqt9PeBAASRluAVQB_4r_j"; private static string _clientSecret = "3138946449429035264"; private static string _username = "c_4less@hotmail.co.in"; private static string _password = "" + _securityToken;

    static void Main(string[] args)
    {
        var auth = new AuthenticationClient();
        auth.UsernamePasswordAsync(_clientId, _clientSecret, _username, _password).Wait();

        var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);

        var results = client.QueryAsync<dynamic>("SELECT Id, Name FROM Account");
        results.Wait(1000);

        var accounts = results.Result.records;

        Console.WriteLine(accounts.Count);
    }
}

}

wadewegner commented 10 years ago

I slightly updated your code so that I could look at the exception.

image

As you can see, API is not enabled for your organization/partner. You could have also used Fiddler to see the error message better.

Note: it's not a good idea to share your credentials like this; hopefully you'll change them quickly.

Hope this helps!