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
Varun Sinha 17Varun Sinha 17 

Web service callout failed: WebService returned a SOAP Fault: Fail creating session for token

I have a visual force page that is calling an external web service and whenever I invoke the method on the web service I get this error.

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Fail creating session for token 'oEP0N1VHM4yLFOytdDwSSRpuXsW+s4LMnypVDYU8/X8afi3kUJxen26ZStVyyy5s'. faultcode=soap:Server faultactor=

Any help would be greatly appreciated. 
pconpcon
Can you please provide the Apex code that you are using to make this callout?  Are you able to successfully make the call to the SOAP endpoint with the same payload using an external tool such as cURL or SOAPui?
Varun Sinha 17Varun Sinha 17
The apex code which I am writing is

global class SoapEDSClass {
    public string userName{get;set;}
    //public string userName1{get;set;}
    public string userGroup{get;set;}
    //public string userGroup1{set;}
    //public string username1{get;set;}
    public string systemDate{get;set;}
    public string token{get;set;}
    public string getgenerateToken{set;}
    public string encryptedKey{get;set;}
    public SoapEDSClass(){
        String locale = 'en';
        userGroup=System.Label.UserGroup;
        userName=System.Label.UserName;
        encryptedKey = getgenerateToken(userName,userGroup);
        // System.debug('>> encryptedkey >> ' + encryptedKey);
       // Datetime yourDate = Datetime.now();
       // Datetime yourDate1 = System.now();
        //string sessionID=login(encryptedKey,'en');
        //systemDate=yourDate.format('yyyyMMddhhmmss');
        //TimeZone tz = UserInfo.getTimeZone();
        //System.debug('The time is'+yourDate);

        //System.debug('The time one is'+yourDate1);

        token=userName+';'+userGroup+';datetime-'+systemDate;
        string session=login(encryptedKey,locale);
        System.debug('The session id'+session);
    }
    @RemoteAction
    global static string getgenerateToken(string userName,string userGroup){
        Blob key = Crypto.generateAesKey(128);
        
        string passPhrase = 'wEC38PruRaSw.bEm';
        Blob secretKey = Blob.valueOf(passPhrase);
        
        Blob tokenString = Blob.valueOf(getToken(userName,userGroup));
        //return tokenString;
      // Blob encryptedStr = Crypto.encryptWithManagedIV('AES128', secretKey, tokenString);
           Blob encryptedStr = Crypto.encrypt('AES128',secretkey,secretKey,tokenString);       
        System.debug('>> encryptedStr >> ' + encryptedStr);
        String encodedEncrypedStr = EncodingUtil.base64Encode(encryptedStr);
        System.debug('>> encodedEncrypedStr >> ' + encodedEncrypedStr);
        return encodedEncrypedStr;
    }
    
    //Generate token based on the passed user name and group
    public static String getToken(String userName, String userGroup){
        //DateTime dt = DateTime.now();
        DateTime dt = System.now();
        //String dt1=dt.formatGMT('hhmmss');
        //String dt2=dt.format('yyyymmdd');
        //System.debug('The dt1 is'+dt1);
        //System.debug('The dt2 is'+dt2);
        String dateTimeStr = dt.formatGMT('yyyyMMddhhmmss');
        System.debug('The datetimeStr is'+dateTimeStr);
        String tokenStr = userName+';'+userGroup+';datetime-'+dateTimeStr;
        System.debug('>> tokenStr >> ' + tokenStr);
        return(tokenStr);
    }
    @RemoteAction
    global Static string login(String tokenID,String locale){
        //global static wwwKaidaraComKaidaraserviceCSS.kaidaraSession login(String tokenID,String locale)    {
        // Http httpProtocol = new Http();
        
        String username =  'cssapp'; //"scharette';
        String password = 'css4ever'; //"";
        //HTTPRequest r = new HTTPRequest();
        //string endpointurl='https://edstest.ptcmanaged.com/wservice/services/KaidaraService';
        //r.setEndpoint(endpointurl);
        Blob beforeblob = Blob.valueOf(username+':'+password);
        string paramvalue = EncodingUtil.base64Encode(beforeblob);
        //r.setMethod('POST');
        // r.setHeader('Authorization', authorizationHeader);
        
        wwwKaidaraCom.loginWithToken loginDetails = new wwwKaidaraCom.loginWithToken();
        loginDetails.locale=locale;
        loginDetails.token=tokenID;
        String authorizationHeader = 'Basic ' + paramvalue;
        //r.setHeader('Authorization', authorizationHeader);
        wwwKaidaraComKaidaraservice.kaidaraSession sesID = new wwwKaidaraComKaidaraservice.kaidaraSession();
        //wwwKaidaraComKaidaraserviceCSS.kaidaraSession sesID = new wwwKaidaraComKaidaraserviceCSS.kaidaraSession();
        //wwwKaidaraCom.loginWithTokenResponse sesID = new  wwwKaidaraCom.loginWithTokenResponse();
       // wwwKaidaraComCSS.KaidaraServiceImplPort wsCall = new wwwKaidaraComCSS.KaidaraServiceImplPort();
        wwwKaidaraCom.KaidaraServiceImplPort wsCall = new wwwKaidaraCom.KaidaraServiceImplPort();
        wsCall.inputHttpHeaders_x = new Map <String, String>();  
        wsCall.inputHttpHeaders_x.put('Authorization', authorizationHeader);
        //HttpResponse response = httpProtocol.send(r);
        //System.debug(response);
        sesID = wscall.loginWithToken(loginDetails.token,loginDetails.locale);
        string a=string.valueOf(sesID);
        System.debug('The string is'+a);
        System.debug('The sess ID is'+sesID.key);
        System.debug('The name is'+sesID.name);
        //return sesID;
        return a;
        
    }
    /*public Static wwwKaidaraComKaidaraservice.kaidaraSession doWebServiceLogin(wwwKaidaraComKaidaraservice ks, String UserName, String Password,String UserGroup,String Address,String tknUser) {
wwwKaidaraComKaidaraservice.kaidaraSession sesID=NULL;
sesID=wwwKaidaraCom.loginWithToken(UserName,'en');
return sesID;
}*/
}


From SOAP UI WHEN I AM PASSING THE TOKEN, Error which I am getting is

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>Fail creating session for token 'oEP0N1VHM4yLFOytdDwSSRpuXsW+s4LMnypVDYU8/X8q4vznJ0epj60Rhce8ksw/'.</faultstring>
         <detail>
            <ns1:Exception xmlns:ns1="http://www.kaidara.com/"/>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>


Can you let me know what the problem is?Thanx in advance
pconpcon
This appears to be an issue with how the SOAP endpoint you are using and not with Salesforce.  Once you can get a valid SOAP request that works in SoapUI, then you'll need to transfer that format into your Visualforce Controller.
Varun Sinha 17Varun Sinha 17
so that means that the endpoint url is not correct?
pconpcon
Since you are getting an actual faultstring back from the SOAP endpoint, that means that you are not passing the expected data and / or the endpoint is not functioning properly.  If the endpoint URL was incorrect you would not get a soapFault you would get a 404 response.
Varun Sinha 17Varun Sinha 17
I was able to make a connection with them.But now when I am trying to call another method I am getting this error :

System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element diagnosticSessionStatus.

Can you help me with this?
Thanx