Integrating salesforce SOAP API using C# .NET

Salesforce can be integrated with any .NET based application through the salesforce SOAP API. This article will show how to connect to salesforce and consume data within ASP.NET application.

Before we begin, there are a set of prerequisites that you need to get done in order to interact with salesforce API using the C# .NET.

  • Username and Password (salesforce logins)
  • SOAP API (WSDL file)
  • Security Token

Username and Password

You can register for a developer license in case you don’t have a user name and password at https://developer.salesforce.com/signup

SOAP API (WSDL file)

To get WSDL SOAP API, need to login salesforce and click “Set up” on right top Corner. Then go Develop > API and right click on “Generate Enterprise WSDL” under Enterprise WSDL (as we using “Enterprise WSDL” web service) and click on “Save Link as….” to save (enterprise.wsdl) file to somewhere in your computer.

Security Token

My Setting > Personal > Reset My Security Token

.NET Application

Let’s start exploring the SOAP API functionality by creating a sample .Net application and connect into Salesforce.

Here are the steps that can be taken to setup the Enterprise WSDL:

Create new ASP.NET Empty Web Site

Adding a Web Service Reference to website

select “Add Service Reference”.

Click “Advanced..”

Click “Add Web Reference…”

In Add Web Reference dialog type path of saved “enterprise.wsdl” file in URL: and click “Enter” then change Web reference name to “SFDC” then click “Add Reference”.

Now Salesforce SOAP API added into our website

Now that the base website is created and a reference setup to the Enterprise WSDL, we can transition to writing code that calls the API.

The first step is to have Salesforce authenticate us as a user. Once the authentication with Salesforce is successful, additional authentication information, such as the Session ID and URL will be returned. This information is needed for subsequent API calls.

The Session ID can be cached in your application for periods less than the timeout period. Go to “Setup > Security Controls > Session Settings” to see what your timeout is.

Here is example code showing how to authenticate against Salesforce :

using SFDC;
protected void Page_Load(object sender, EventArgs e)
{
    bool ConnectionStatus;
    ConnectionStatus = ConnectSFDC();
    //rest of the code
}

public bool ConnectSFDC()
{
     string userName = "ujjwaladatta@uzval.com";
     string password = "...";
     string securityToken = ".........";

     System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
     SforceService sfdcBinding = null;
     LoginResult currentLoginResult = null;

     sfdcBinding = new SforceService();
     try
       {
           currentLoginResult = sfdcBinding.login(userName, password + securityToken);
       }
     catch (System.Web.Services.Protocols.SoapException ex)
       {
                // This is likley to be caused by bad username or password
                sfdcBinding = null
                //lOG ex
                return false;
        }
      catch (Exception ex)
        {
              // This is something else, probably communication issue
                sfdcBinding = null;
                //lOG ex
                return false;
        }
       //Change the binding to the new endpoint
       sfdcBinding.Url = currentLoginResult.serverUrl;
       //Create a new session header object and set the session id to that returned by the login
       sfdcBinding.SessionHeaderValue = new SessionHeader();
       sfdcBinding.SessionHeaderValue.sessionId = currentLoginResult.sessionId;
       // create required sessions 
       return true;
 }
Advertisements

Enterprise Applications Integration -Overview

E A I – Breaking down information barriers across the Enterprise

Image

Overview :

As enterprises spread their boundaries across different business areas, they acquire disparate technology solutions, technologies and applications. However, these applications are often unable to communicate and share information with each other due to several reasons like lack of interoperability, variable formats and dissimilar standards of operations.

Supply chain management applications (for managing inventory and shipping), customer relationship management applications (for managing current and potential customers), business intelligence applications (for finding patterns from existing data from operations), and other types of applications (for managing data such as human resources data, health care, internal communications, etc.), ERP (For Resource Planning), Portals (for Operations) typically cannot communicate with one another in order to share data or business rules. For this reason, such applications are sometimes referred to as islands of automation or information silos. This lack of communication leads to inefficiencies, wherein identical data are stored in multiple locations, or straightforward processes are unable to be automated.

Even in our enlightened times, great amounts enterprise data lies locked away in monolithic applications. Whether they be purchased, home-grown, or a combination, the realities of business demand that the information contained in those vertical ‘silos’ be used in ways that the original architects never intended.

Enterprises are also increasingly looking forward to reconfigure their business processes through tighter integration of applications via rich frameworks, by opting for Enterprise Application Integration (EAI). This is with the intention to achieve effective communication across various business applications and delivery channels, thereby, ensuring seamless data integration from disparate systems

 Enterprise Application Integration:

 Enterprise application integration is an integration framework composed of a collection of technologies and services which form a middleware (Remote Procedure Call, Object Request Broker, Batch Data Communication, Business Application Programming Interface, Service Oriented Architectures) to enable integration of systems and applications across the enterprise.

Enterprise Application Integration practice expertise focuses on:

Opening up ways for the information to flow from one application to another,

Letting applications to reach other sources of data outside themselves,

and Allowing other programs to peer into the innards of formerly closed programs.

Sharing data between divisions or even between separate corporations

Image

and i wanted to discuss more about this challenge architecture in next couple of articles along with Implementations too which are observed by me since long time.