+ Start a Discussion
gaurav.agrawal91.3963408275063662E12gaurav.agrawal91.3963408275063662E12 

webservice callout error

Hi,

I am trying to consume web service that I have created in Salesforce from a different org of Salesforce. And am getting the following Exception
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=:
Vinita_SFDCVinita_SFDC
Hello,

You cannot get the session ID when running a batch:

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_userinfo.htm

Look up "getSessionId()" usage.

Refer: https://developer.salesforce.com/forums?id=906F00000008lRVIAY
gaurav.agrawal91.3963408275063662E12gaurav.agrawal91.3963408275063662E12
Here i am developing the webservice in salesforce and calling that webserice also in salesforce but in different org.

Please find the code below.

Target webservice:

global class HelloWorldWebService {
    webService static string sayHello() {
     return 'Hello World!';
    }
}


Client prog:

public class sayHello
{
public sayHello()
{
}
public string getoutput()
{
partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult loginResult = sp.login(' (mailto:'@genpact.com')Targetuserid, Password + secuity token);
system.debug('   loginResult ' + loginResult);
soapSforceCom200608Apex.Apex apexWebSvc = new soapSforceCom200608Apex.Apex(); 
soapSforceCom200608Apex.SessionHeader_element sessionHeader = new soapSforceCom200608Apex.SessionHeader_element(); 
sessionHeader.sessionId = loginResult.sessionId;  
apexWebSvc.timeout_x = 120000; 
apexWebSvc.SessionHeader = sessionHeader;

soapSforceComSchemasClassRavinsHel.HelloWorldWebService obj=new soapSforceComSchemasClassRavinsHel.HelloWorldWebService();
string s= obj.sayHello();
return s;
}
}


And calling this apexcontroller through Visual force page:

<apex:page controller="sayHello">
<apex:outputText value="{!Output}"/>

</apex:page>


I am getting below excpetion :

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=

Can any one please help me here.