function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TwEEkTwEEk 

Apex WSDL: login/URL issue

I need to call the compileandtest function.

 

I use the following code to login (note the username/password are from a sandbox)

 

 

ApexWSDL wsdl = new ApexWSDL();

SforceService sforce = new SforceService();
LoginResult result = sforce.login(Username, Password);

SessionHeader sh = new SessionHeader();
sh.sessionId = result.sessionId;
wsdl.SessionHeaderValue = sessionHeader;

 

If I do NOT set the URL, it leaves it set to: https://cs1-api.salesforce.com/services/Soap/s/17.0

 

and when I make the call CompileAndTest, it throws the following error: 


INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key

 

If I set it by using the following:

 

 

wsdl.Url = result.serverUrl;
/*
* results in:

* https://tapp0-api.salesforce.com/services/Soap/u/17.0/00DT0000000Gg4n
*/

 OR

 

wsdl.Url = result.metadataServerUrl;
/*
* results in:

* https://tapp0-api.salesforce.com/services/Soap/m/17.0/00DT0000000Gg4n
*/

Then when I make the call CompilAndTest it throws the following error:

 

"No operation available for request {http://soap.sforce.com/2006/08/apex}compileAndTest"

 

can somebody help here?

 

 

 


 

 

Message Edited by TwEEk on 03-02-2010 02:49 PM
Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
the apex wsdl is specific to the instance you downloaded it from, you can either download one for each instance you use, or as i suggested at runtime update the binding url (by replacing the hostname) with the host name from the serverUrl returned by the login call.

All Answers

SuperfellSuperfell
If you're login is for cs1, then the default URL should work.
TwEEkTwEEk

What do you mean by cs1?

 

The above example does NOT work.

 

SuperfellSuperfell
when you login to the web with the same credentials, what URL do you end up at ?
TwEEkTwEEk

Using the same credentials:

 

https://tapp0.salesforce.com/home/home.jsp

 

SuperfellSuperfell
That's a different instance to the one you downloaded the WSDL from, you can either download a fresh WDSL, or add something to fixup the host part of the URL for the apex stub based on the serverUrl from the login result. 
TwEEkTwEEk

So your saying you need a seperate WSDL from sandbox and a seperate WSDL for live/prod?

 

Or just a new instance of each WSDL for each environment/sandbox?

SuperfellSuperfell
the apex wsdl is specific to the instance you downloaded it from, you can either download one for each instance you use, or as i suggested at runtime update the binding url (by replacing the hostname) with the host name from the serverUrl returned by the login call.
This was selected as the best answer
TwEEkTwEEk

Cheers SimonF,

 

 

For others with similar issue, the following code sets the Url:

 

 

Uri defaultUrl = new Uri(wsdl.Url); Uri sessionUrl = new Uri(sforce.Url); string targetUrl = "http://" + sessionUrl.Host + defaultUrl.PathAndQuery; wsdl.Url = targetUrl;

 

 

 

SuperfellSuperfell
Just one thing, you really should use https
TwEEkTwEEk

HA! Good point.

 

Hence why its always good to have two eyes on the code :p