1

I'm creating a .Net application to consume the Soap APIs.

I downloaded 2 partner wsdl files from 2 instances(production and sandbox). I think the only difference of the two APIs are their endpoints.

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!

sfdcnoob
  • 777
  • 2
  • 8
  • 19
  • If those APIs are the same (they are just in different environments) from what I remember you should be able to just change URL endpoint on proxy class. Just load URL which you are targeting from some config. See also if this answer can help you: http://stackoverflow.com/questions/125399/how-can-i-dynamically-switch-web-service-addresses-in-net-without-a-recompile – nikib3ro Jul 11 '15 at 04:13

1 Answers1

0

If the services are truly the same and just the endpoint differs, you should be able to use the generated client's Endpoint property to change the endpoint.

var client = new ServiceReference1.WebService1SoapClient();
client.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:2850/WebService1.asmx");
Daniel
  • 1
  • 1