I am trying to connect two Salesforce Org and create a case in Client SFDC org via SOAP API by using WSDL files at both end.
I have used following code at server for WSDL file generation(and used Partner WSDL API):
global class CaseServer{
webservice static string CreateCase (String Status, String Origin){
Case Newcase= new Case();
Newcase.Status = Status;
Newcase.Origin = Origin;
try {
insert Newcase;
return 'Success';
} catch (DmlException e) {
return e.getMessage();
}
}
}
I executed below anonymous block in client sfdc:
string username='MyUsername';
string password = 'MyPassword';
partnerSoapSforceCom.LoginResult sessionInfoObj = new partnerSoapSforceCom.LoginResult();
partnerSoapSforceCom.soap soapObj = new partnerSoapSforceCom.soap();
soapObj.login(username,password);
soapCaseserver.SessionHeader_element sessionElemnetObject = new soapCaseserver.SessionHeader_element();
sessionElemnetObject.sessionId = sessionInfoObj.sessionId;
soapCaseserver.CaseServer wsobj = new soapCaseserver.CaseServer();
wsobj.SessionHeader = sessionElemnetObject;
wsobj.CreateCase('New','Phone');
Error: Error: System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session faultcode=sf:INVALID_SESSION_ID faultactor=
Basic Checks that i performed:
Ip range is from 0.0.0.0 to 255.255.255.255 in Server
Not appended security token, as already allowed all ip range, as per
above point.
Above code is performed in client anonymous window.
Added both end point url in client Remote site settings.
Tried to create a case with above two parameters. Case was
successfully created in Server.
When i execute above code, there is successful login in Server. It
is visible in login history.
Can anyone please suggest what i am missing out here??