Search code examples
asp.net-mvc-3salesforceweb-reference

Update web service at runtime


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.


Solution

  • 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.