Question

I need to authenticate users and get info about them from an ASP.Net application. Since I have 2 sites (sandbox, production) and 2 org IDs - I needed to generate 2 SalesForce WSDL files.

I diffed the 2 files (each about 600kb in size) and while they are 95% the same, there are enough differences strewn all over the place - enough for me to need to use them both. I added both as web references to my solution, and here's where my problem starts.

Obviously, I cannot use both references in the same file, as they contain the same classes/functions. I had to write a quick-and-dirty solution over the weekend, so I just created 2 classes - each using a different web reference - but otherwise the exact functionality, and I use the appropriate one, based on the URL the user is coming from. This works well, but strikes me as a bad (read: quick-and-dirty) solution.

My question: is there any way to do one or more of the following:

  1. change the web reference on the fly?
  2. use both web references in the same file, but put one in a different namespace?
  3. find a better solution to the whole situation? I nd up with a huge XmlSerializer.dll (3mb!) - probably due to using both huge WSDL files.

Thanks for your time.

Was it helpful?

Solution

Actually, the solution was much easier and was hiding under my nose.
I just needed to use Namespace aliases. That way, I can include both services in compile time, and decide which to use at runtime:

using System.Web;
.
using ProductionAPI = MyCompany.SForce;
using SandboxAPI = MyCompany.SForce.Sandbox;
.
.
.
if(isSandbox)
  binding = new SandboxAPI.SForceService();
else
  binding = new ProductionAPI.SForceService();
.
.
.

OTHER TIPS

It might be I am missing something but I will try to answer:

1 I assume you mean the URL? Yes you can when creating the client object

var service = new Acmeco.AcmecoService();
service.Url = "oneUrlOrTheOther;   

2 What do you mean? When you add the reference you have to give it a name which puts it in a unique namespace. Like Acmeco in the previous example.

3 That kind of depends on what in that 5% difference you mention? I don't quite understand how you end up with a difference in the WSDL for the same webservice on two different hosts. I would think only the addresses would be different but the methods and parameters would stay the same. Perhaps you can ellaborate?

What are the differences between them? I suspect it's just aht SalesForce.com is very customizable, so that your sandbox and production sites are not identical. The two need to be identical if you're going to take advantage of the ability to use the sandbox site for testing.

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