Question

I have a MVC application which i m integrating with slaesforce. And it is working fine, salesforce provied WSDL which is used in/as a web reference in MVC application and successfully access salesforce data. Now i m in a situation where i need to use salesforce sandbox.

So i have two WSDLs generated from Salesforce one for Production and another for Sandbox. But can not add both to the MVC project at the same time as both have same objects.

What i need to do is to changes Webservice Url or something on some condition to use Production WSDL one time and Sandbox WSDL another time.

So it would be something like this

//The Action used in salesforce site to send submit order email
public string SendSubmitOrderEmail(string opportunityId,bool isSandbox)
{
   if(isSandbox)
   {
      SforceService sf = new SforceService();
      sf.Url = "https://test.salesforce.com/services/Soap/";
   }
   else
   {
      SforceService sf = new SforceService();
      sf.Url = "https://login.salesforce.com/services/Soap/";
   }
}     

OR can i change webservice settings in webconfig?

<applicationSettings>
<ItineraryBuilder.Properties.Settings>
  <setting name="ItineraryBuilder_SalesForceService_SforceService"
    serializeAs="String">
    <value>https://login.salesforce.com/services/Soap/c/25.0/0DFd00Wa6</value>
  </setting>
</ItineraryBuilder.Properties.Settings>
</applicationSettings>

Not sure how to do.

Thanks for any help.

Was it helpful?

Solution 2

Thanks all,

Updating Web reference at runtime works fine

SforceService sf = new SforceService();
sf.Url = "test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6"

what i was doing wrong, the "sf" was not passed to API class which is used in creating connection.

i got solution in my another question here

Update web.config applicationSettings programmatically with C# (MVC)

Thanks again.

OTHER TIPS

You should set the endpoint url (and other config info like username, password etc) in an external properties file, and then your code will then access this key-value properties file to retrieve the endpoint url and config info to connect to salesforce.

url=https://test.salesforce.com/services/Soap/

username=blah@blah.org.sandbox

pasword=blahxxxx12345sxxx

Ideally, you should have seperate properties file for sandbox/dev (dev.properties) and production(prod.properties), and your build system (maven or similar) should pick up the right properties file based on where it is run.

You should avoid hardcoding the url's or determing the environment in your code as much as possible. The above technique should work for oop languages like Java, C++, Python etc.

Hope this makes sense!

Anup

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top