2

I'm creating a .Net application to consume the Soap APIs I downloaded 2 partner wsdl files from 2 instances(production and sandbox). I then added the web references to a single application. When I write the method to consume the APIs, I don't want to duplicate the code to do same thing(insert,update...).

How can I design my code so maybe I can pass a parameter to let the method know which target instance should it talk to?

Thank you!

2

If you difference the two WSDL files, the only difference your should see (apart from a comment timestamp) is this location for the binding at the bottom:

Production:
<soap:address location="https://login.salesforce.com/services/Soap/u/34.0"/>

Sandbox:
<soap:address location="https://test.salesforce.com/services/Soap/u/34.0"/>

I am not familiar with the code that .Net generates, but you should be able to set or otherwise override that value (search for it in the generated code and see) which in combination with a different username/password will allow you to connect to either org.

PS

Based on one of the answers to How to programmatically modify WCF app.config endpoint address setting?, the code may look something like this:

string location = "https://test.salesforce.com/services/Soap/u/34.0";

WSHttpBinding binding = new WSHttpBinding();
EndpointAddress endpoint = new EndpointAddress(new Uri(location));

SforceServiceClient client = new SforceServiceClient(binding, endpoint);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.