BizTalk, SalesForce and MSMQ – Part I

In this and following blogposts I would like to share my experience with integrating SalesForce with a fictive system via MSMQ (fictive system could be ERP, package application, service, ect). Integration is facilitated by BizTalk Server 2009 running on one of my VM machines (hosted by Hyper-V, see BizTalk Virtual Machines with Windows 2008 R2 Hyper V).

SalesForce is a leading CRM software solution that runs in the cloud and can be viewed as software as a service (SaaS). SalesForce itself states it is a leader in CRM (true if you consider their offering as off-premise software) and platform as a service. Latter sounds optimistic as there are some similarities with Microsoft Azure, which is also viewed as platform as a service with richer set of capabilities and a lot more flexibility. SalesForce is more targeted on CRM and you can build applications around it that can be hosted in the cloud or develop services, which I did and I am not the only one. I was inspired by Richard Seroter’s post and the fact that I had to do a POC integrating SalesForce (CRM) with Navision (Finance).

Prerequisites for anyone who would like to integrate with SalesForce is to setup an account with SalesForce to have an development environment (Sandbox) available to build.

image

Second is having an BizTalk development environment (VS 2008, SQL Server 2008) with connection to internet. If you filled in the details, accept agreement and submit, you will receive an email in couple of minutes you can use to login. After login you need to one time change the password.

image

Once that is done you can start setting some things in SalesForce listed down below:

1. Adding an account

image

Note: language here is Dutch as it is localized.

2. Save and add some detail to account

image

image

3. Now I can go to APEX classes and develop some code

image image

Notice that if you click save after developing some code, it will compile and tell you if there is an error. If syntax is correct and code compiles then you will something similar as below.

image

To have access to this created web service you need to have a security token and your credentials. As stated on their site they mention the following:

When accessing salesforce.com from outside of your company’s trusted networks, you must add a security token to your password to log in to the API or a desktop client such as Connect for Outlook, Connect Offline, Connect for Office, Connect for Lotus Notes, or the Data Loader. For security reasons, your security token is delivered to the email address associated with your account. To reset and send your security token, click the button below.

image

You basically have to reset your security token, because it will not be provided when you create an account with SalesForce. If you provide security token you will receive a INVALID_LOGIN error.

image

Security token is necessary to setup session and reuse it (see also code Richard Seroter created for his solution).

Another thing you need to do is to generate Enterprise WSDL. Each SalesForce.com sandbox (like mine) has its own WSDL file (enterprise.wsdl). To access the Force.com Web service, you need this WSDL file. It defines the Web service that is available to you. Your development platform uses this WSDL to generate an API to access the Force.com Web service it defines. You can either obtain the WSDL file from your organization’s Salesforce.com administrator or you can generate it yourself if you have access to the WSDL download page in the Salesforce.com user interface. Click Setup Develop API to display the WSDL download page. For more info see SalesForce API Quickstart.

image

You can save the WSDL to file.

image

I created an empty solution called SalesForce.Integration.POC and a created helper class called BTSSFHelper, through creating C# class library (SalesForce.Integration.POC.BTSSFHelper). Next is to add service reference to enterprise.wsdl. I tried through service referenc, but it somehow does not compile:

Error = "Error 101 The namespace 'SalesForce.Integration.POC.BTSSFHelper.SvcSFRef' already contains a definition for 'ExceptionCode' C:\Projects\SalesForce.Integration.POC\SalesForce.Integration.POC.BTSSFHelper\Service References\SvcSFRef\Reference.cs 808 17 SalesForce.Integration.POC.BTSSFHelper"

I did a workaround by deleting service reference and add web service reference (that is the old way or at least VS 2005 way) through service reference –> advanced –> Add Web Reference.

image

If I build now there is no problem. Next step was to sign the helperclass with a strong name and rebuild. Next is to create a new BizTalk Project called SalesForce.Integration.POC.Solution to add to the solution. In this project I like to consume the web service I build in SalesForce. I need wsdl from my service, so in SalesForce I navigate to Apex classes and generate WSDL.

image

WSDL like enterprise one I save to file. I then go to Add Generated Items --> Consume WebService and walk through the wizard (Metadata Files –> WSDL from file –> Add WSDL –> Import).

clip_image002[6]

clip_image002[8]

clip_image002[10]

Now I all set to consume my SalesForce web service within an orchestration. This is will be discussed in my next post Part II together with interaction with MSMQ. I hope by now some of steps are clear to setup an environment in SalesForce to create a web service and necessary security.

Cheers!


Technorati:

Comments

Unknown said…
Excellent blog post part 1 & 2

Great work, compliments Richards one very well

Conor
BizTalk France said…
Steef, please note that your code is bugged. First the diff.Minutes cannot exceed +/- 59 so the condition diff.Mintues > 60 is always false.

I would suggest also to check that the diff.Hours > 0, because 1hour 5 minutes returns :
diff.Minutes = 5
diff.Hours = 1
Genuine Basil said…
Thank you Steef for sharing this. You may need to reset the '_sessionDate' to current date before returning the '_sessionId'. I was getting same session id after 60 mins and salesforce service was failing.

Regards,
Genuine
Thanks for your experience.
Allan said…
IT companies are gaining popularity with every passing day and tend to grow at a rapid speed.Software development company procedures are getting purifies and verified with a brilliant merge of existing and new technologies everyday. Due to the massive demand of automation and perfection, many organizations are now opting outsourcing software development in order to meet their business needs.

Popular posts from this blog

DTAP Strategy: Pricing and Licensing

Table Operation on Oracle 11g XE with OracleDbBinding

BizTalk Server 2010 Exam : How to prepare?