Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Salesforce Webservice API using C#

Tags:

c#

salesforce

I havent worked with that Salesforce API before, so I am a bit stuck on how to connect to the salesforce service.

So far I understood that I have to generate a wsdl file for my account or rather the account of my customer (step 1). So far, so good.

But now the Quickstart (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_quickstart_steps.htm) says something about "Import the WSDL File into your development platform" (step 2).

How do I import a wsdl file into Visual Studio 2008? I cant find the "Add Web Reference" option which is mentioned in the quickstart.

And if I only need to use the WSDL, what use has the Salesforce Dotnet API package which can be downloaded from the salesforce website (http://wiki.developerforce.com/index.php/Salesforce_Dotnet_API)?

Are there any gotchas I should watch out for when developing applications that use the salesforce API?

like image 274
Max Avatar asked Oct 07 '09 13:10

Max


2 Answers

If you follow the directions in Binz' answer, you should be able to add a web service reference using Visual Studio.

The "Salesforce Dotnet API package" on the wiki site is not required to access the SalesForce API, it's just a library that tries to abstract it.

As far as gotchas and other things to know, I would recommend that you read chapter 6 of the Force.com Cookbook. You have to sign up for a force.com developer account (free). Most of the things you'll need to be aware of are covered in this chapter. Here are a few of them:

  • logging in / logging out - session management
  • query / queryMore pattern (needed if you're going to pull large sets of data from SalesForce)
  • how to construct a wrapper class - there is some sample vb.net code you can download as well

One other thing to note, if you're going to use SOQL to query your SalesForce data, and you need to filter on a SalesForce date field, you'll need to format the date string. Here's one way to do it:

public static string FormatDateForQuery(DateTime dateToFormat, bool includeTime)
{
    if (includeTime)
    {
        return dateToFormat.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss+00:00");
    }
    else
    {
        return dateToFormat.ToUniversalTime().ToString("yyyy-MM-dd");
    }
}
like image 140
Adam Butler Avatar answered Nov 14 '22 12:11

Adam Butler


For Visual Studio 2008 you need to select 'Add Service Reference', then click the 'Advanced' button on the bottom left of the dialogue. There should then be a button on the bottom of that dialogue that says 'Add Web Reference'. You should be able to then select your wsdl file and a service client proxy will be auto genned for you by VS.

like image 9
Binz Avatar answered Nov 14 '22 12:11

Binz