I know there are multiple posts related to this exception and I've gone through them, but I can't seem to find a solution.
I am trying to call a custom web service provided to us by a customer. We used a Partner WSDL previously for making other 'describeObject' type calls to the API. But now, we need to call the web service method exposed by the customer's WSDL. I added the custom WSDL as a web reference on my project.
I'm able to get the session id and server url by calling the sForceService.login(username, password) method. But the subsequent call to the customer's web service method fails with an 'Invalid SessionId' exception. Customer's account is a Sandbox account.
Here is the code:
//_sforceService: Salesforce Partner WSDL reference.
_sForceService = new SforceService();
_sForceService.Url = "https://test.salesforce.com/services/Soap/u/28.0"; //Is this correct? if I don't assign this, the login fails
_loginResult = _sForceService.login("username", "Password+security token");
//ucGuideBook.GIA_ServiceService is Customer's webservice.
ucGuideBook.GIA_ServiceService ucGIAService = new GIA_ServiceService();
ucGIAService.SessionHeaderValue = new ucGuideBook.SessionHeader();
ucGIAService.SessionHeaderValue.sessionId = _loginResult.sessionId;
//This call fails:
string ucGuideBook = ucGIAService.getGuidebookXml("AccountId");
INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session. Session not found, missing session key:
It seems like it's going to a different Sandbox than the one that has the active session. It might have something to do with the WSDL endpoint, I'm not sure. The WSDL end point is: https://cs2.salesforce.com/services/Soap/class/ClassName.
The serverUrl that is returned from the .login() method: "https://mysandbox.cs13.my.salesforce.com/services/Soap/u/28.0/OrgId" . I tried changing the wsdl end point to be cs13, but that didn't help.
I looked at existing forum answers, and ensured this setting was off - "Lock sessions to the IP addresses from which they originated" (doesn't make a difference whether it is ON or OFF), and could not find anything else relevant.
Any help would be greatly appreciated.