Seroter has shown us how to call the Force.com REST API from BizTalk Server and we used this to successfully call standard Force.com objects like .salesforce.com/services/data/v34.0/sobjects/contacts”>https://<blah>.salesforce.com/services/data/v34.0/sobjects/contacts. We could not use this to call custom force.com objects like .salesforce.com/services/apex/ContactMapping”>https://<blah>.salesforce.com/services/apex/ContactMapping unless we modified the published WCF Behaviour for authentication. Thanks to Aravindh Kathiresan for working all this out. The purpose of this blog is to share how we modified this behaviour and as a memory dump for me.
We started from code shared by Muhummad Ehsan. The Force.com login endpoint is hard coded to https://login.salesforce.com/services/oauth2/token when calling the REST API authentication service. We had to change this to .salesforce.com/services/oauth2/token”>https://<blah>.salesforce.com/services/oauth2/token . First we changed this line of code in SfdcTokenManager.cs to dynamically assign the Force.com login endpoint.
Secondly we added a new oauthurl configuration property
and changed the return signatures to
The OAuthURL was added to the struct in the RestAuthConfiguration.cs.
Finally the SfdcRestAuthBehavior.cs was refactored to include the OAuthURL.
After deploying the modified behaviour an authentication endpoint can be configured on the endpoint behaviour as shown below;
In summary we have shown how to dynamically configure a Salesforce authentication endpoint in a custom endpoint behaviour. This can be used to call a REST API with a custom Apex endpoint.