Monday, 6 April 2009

C# Salesforce Development

You will need the following:
  1. Visual Web Developer Express Edition
  2. Salesforce Developer Account
  3. WSDL generated by the salesforce account (http://www.salesforce.com/us/developer/docs/api_meta/index.htm)
  4. in VWD create a website, not a web project (this si a personal preference)
  5. Website -> Add Web Reference -> URL = your Enterprise.wsdl
  6. web reference name = "salesforce"
  7. Add Reference
now how do you use any of this? We need to expose the salesforce API functionality to the c# program
  1. in your App_Code folder create a class called sfconnector.cs
public salesforce.SforceService doLogin()
{
salesforce.SforceService binding = new salesforce.SforceService();
try
{
salesforce.LoginResult lr = binding.login(sforceUsername, sforcePassword);
binding.SessionHeaderValue = new salesforce.SessionHeader();
binding.SessionHeaderValue.sessionId = lr.sessionId;
binding.Url = lr.serverUrl;
binding.Url = lr.serverUrl;
}
catch (Exception)
{ }
return binding;
}

this will connect you to salesforce provided you have the correct username and password. If we can log in we probably want to log out as well.

public void logOut(Page pg)
{
pg.Session.Abandon();
pg.Response.Write("");
}

By calling this function we'll terminate the current session.

No comments:

Post a Comment