What are the Steps of Salesforce and Asp.net Integration?

  6358

As publicized, Salesforce (Force.com or SFDC) is Number one on-demand CRM and is as of now an exceptionally hot innovation in the IT industry. Through SOAP APIs, Salesforce firmly coordinates with different back-end innovations like .NET and JAVA, which gives you, a chance to access as well as control your information and usefulness in the Force.com cloud.

The Force.com stage firmly coordinates with Microsoft .NET innovations by means of the Force.com SOAP API, which gives you, a chance to access as well as control your information and usefulness in the Force.com cloud. This usefulness can be executed on any Microsoft.NET supported platform including but not restricted to web applications running IIS, Windows work area or server applications, SharePoint administrations, and SQL Server Programmability.

Today, we will see how can we integrate Salesforce with the Asp.net. 

Prerequisites

To do any activity we need appropriate session login to Salesforce application and for which an Enterprise WSDL should be produced through which we will verify ourselves in Salesforce to do our tasks. There are three kinds of WSDL types from which Enterprise WSDL will be of our utilization.

Steps by Steps Salesforce and ASP.net Integration

Here are the steps that you need to follow to integrate Salesforce with Asp.net-

Step I (Generate the WSDL)

WSDLs are consequently produced and kept up by the platform. Whatever objects we are making in Salesforce it will be consequently accessible to accompanying WSDL. Moreover, in the event that we are making any web service classes, its WSDL would also be accessible. To get it we can pursue the underneath steps: –

Go to the standard User Interface, get signed in and explore as beneath, Setup then goes to Setup then choose Develop and then pick API.

Pick the suitable WSDL and download the file to an area available to your improvement condition. Or on the other hand, if suitable WSDL expected isn’t there then do as beneath:- Login then go to Setup then to Develop then API and lastly, Click on ‘Produce’ Now we have the WSDL URL to be utilized further.

Step II (Add a reference to WSDL from .Net application)

Visual Studio 2008 and newer now reference ‘Add Service Reference’ to projects and have deprecated the ‘Add Web Reference’ term. Regardless of terminology or versions, the steps to add a reference to your WSDL file are in essence the same across all versions of Visual Studio:

Related Post:  Step by Step Guide for Mailchimp and Salesforce Integration

Visual Studio 2008 and a more up to date reference ‘Add Service Reference’ to ventures and have censured the ‘Add Web Reference’ term. Notwithstanding wording or forms, the means to add a reference to your WSDL document are basically the same all over the adaptations of Visual Studio:

  • Right tap on the venture and pick ‘Add Service Reference’ alternative from the menu.
  • Add Service Reference discourse will be opened, tap on ‘Advanced’ option here.
  • In the ‘Service Reference Settings’ discourse, again tap on ‘Add Web Reference’ option to continue for including Web Reference.
  • In ‘Add Web Reference’ discourse enter the WSDL URL we gathered already and press Enter. Presently it will provoke for salesforce account Username and Password. Give Username and Password and tap on ‘Sign in to Salesforce’ tab.
  • In subsequent stage give an appropriate name to the reference and tap on ‘Include Reference’ tab.
  • Now we can see the web reference included by us in ‘Solution Explorer’ inside our venture’s ‘Web References’ organizer.

Step III (Using the Web Reference)

To do any task, first of all, we require a functioning session to the Salesforce API being built up. For this, we require three things as specified beneath:-

  • Username: Username of the salesforce account through which you need to do all activities.
  • Password: Password of the salesforce account through which you need to do all activities.
  • Security Token: The Security Token isn’t required if the IP of the purchaser is being added to the trusted IP list of the salesforce account generally Security Token is obligatory.
  • A security token is a naturally created from Salesforce. For instance, if a client’s password is spassword, and the security token is XXXXXXXXXX, at that point the client must enter spasswordXXXXXXXXXX to sign in. Or on the other hand, some customer applications have a different field for the security token. 
Get the Security Token:

We can change the Security token through the Salesforce UI. Changing secret key consequently sends another security token to the email address on the client’s Salesforce record or client can do the same utilizing Salesforce interface resetting of a security password.

The security token is valid only until when a client does the underneath activities:-

  • resets their security token straightforwardly
  • changes their password
  • Or has their password reset. 
Steps to generate a new:

Tap on the Username on right most corner of the page >> My Settings >> Personal >> Reset My Security Token. It will reset and make another security token for you which can be utilized for verification in .Net application by connecting with a login password.

Related Post:  How to Integrate Salesforce With Outlook?

Step IV (Authenticate and Create Salesforce API Session in .Net)

You need to declare the required variables:

Here is the code you need to type in

// to store session variable name
private string _username = "salesforce account username";
// to store session variable name
private string _password = "salesforce account password";
// generated tokenid from salesforce
private const string _tokenID = "token id";

// to store session variable name
private string _sessionId;
// next login time
private DateTime _nextLoginTime;
// instance for login result
Private LoginResult _loginResult;
// instance creation for SforceService
Private SforceService _sForceRef;

Next step is to check whether or not the session is valid. For that you need to run the following code

// this is a method used to check if the session is valid or not by checking with
// the session variable name
private bool IsValidSession()
{
bool blnResult = false;
if (!string.IsNullOrEmpty(_sessionId) & _sessionId != null)
{
if (DateTime.Now > _nextLoginTime)
blnResult = false;
else
blnResult = true;
}
else
blnResult = false;

return blnResult;
}
}

Create Session if not valid:

Call the login technique by passing username and password but password ought to be a blend of salesforce client account password and the security token. Ex:

_loginResult = _sForceRef.login(_username, _password + _tokenID);

Get session details from login result and store it into the session factors. Ex:-

_sessionId = _loginResult.sessionId;
Session["SessionId"] = _loginResult.sessionId;
Session["ServerUrl"] = _loginResult.serverUrl;
Session["NextLoginTime"] = DateTime.Now;

iii)   Thereafter you need to launch a proper force.com session to do any supplementary operations

_sForceRef.Url = _loginResult.serverUrl;
_sForceRef.SessionHeaderValue = new SessionHeader();
_sForceRef.SessionHeaderValue.sessionId = _sessionId;

The very last step is to check the session validity before conducting any operation:

You need to see if the present session is valid and create if not valid. Ex:-

if (!IsValidSession())
isError = GetSessionDetails();

Conclusion

Salesforce and Asp.net integration is not a very difficult thing to do if you follow the steps given above diligently. You just need to make sure that the person who is in charge of the integration process knows some basic coding. This is because at certain places you need to run the codes as you must have already understood from the step IV of the integration process.

Write a Comment

avatar
  Subscribe  
Notify of

Download & Learn from Our Whitepapers

Stop, read and acquire deep insights into complex issues