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
Force.comForce.com 

SOAP Integration Salesforce and Swipeclock

Hi, 

 

I am trying to invoke Swipe Clock, an external server through SOAP from Salesforce. I have generated apex class from wsdl file. Generated class is :

//Generated by wsdl2apex

public class mc2csComScci {
    public class AddEmployee_element {
        public String employeeCode;
        public String lastName;
        public String firstName;
        public String middleName;
        public String designation;
        public String title;
        public String ssn;
        public String dept;
        public String location;
        public String supervisor;
        public String startDate;
        public String endDate;
        public Integer lunch;
        public Double lunchHours;
        public Decimal payRate0;
        public Decimal payRate1;
        public Decimal payRate2;
        public Decimal payRate3;
        public String cardnum1;
        public String cardNum2;
        public String cardNum3;
        public String password;
        public String options;
        public String home1;
        public String home2;
        public String home3;
        public String schedule;
        public Integer exportBlock;
        private String[] employeeCode_type_info = new String[]{'employeeCode','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] lastName_type_info = new String[]{'lastName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] firstName_type_info = new String[]{'firstName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] middleName_type_info = new String[]{'middleName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] designation_type_info = new String[]{'designation','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] title_type_info = new String[]{'title','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] ssn_type_info = new String[]{'ssn','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] dept_type_info = new String[]{'dept','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] location_type_info = new String[]{'location','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] supervisor_type_info = new String[]{'supervisor','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] startDate_type_info = new String[]{'startDate','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] endDate_type_info = new String[]{'endDate','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] lunch_type_info = new String[]{'lunch','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] lunchHours_type_info = new String[]{'lunchHours','http://www.w3.org/2001/XMLSchema','float','1','1','false'};
        private String[] payRate0_type_info = new String[]{'payRate0','http://www.w3.org/2001/XMLSchema','decimal','1','1','false'};
        private String[] payRate1_type_info = new String[]{'payRate1','http://www.w3.org/2001/XMLSchema','decimal','1','1','false'};
        private String[] payRate2_type_info = new String[]{'payRate2','http://www.w3.org/2001/XMLSchema','decimal','1','1','false'};
        private String[] payRate3_type_info = new String[]{'payRate3','http://www.w3.org/2001/XMLSchema','decimal','1','1','false'};
        private String[] cardnum1_type_info = new String[]{'cardnum1','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] cardNum2_type_info = new String[]{'cardNum2','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] cardNum3_type_info = new String[]{'cardNum3','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] password_type_info = new String[]{'password','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] options_type_info = new String[]{'options','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] home1_type_info = new String[]{'home1','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] home2_type_info = new String[]{'home2','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] home3_type_info = new String[]{'home3','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] schedule_type_info = new String[]{'schedule','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] exportBlock_type_info = new String[]{'exportBlock','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'https://mc2cs.com/scci','true','false'};
        private String[] field_order_type_info = new String[]{'employeeCode','lastName','firstName','middleName','designation','title','ssn','dept','location','supervisor','startDate','endDate','lunch','lunchHours','payRate0','payRate1','payRate2','payRate3','cardnum1','cardNum2','cardNum3','password','options','home1','home2','home3','schedule','exportBlock'};
    }
    public class EmployeeWebInterfaceSoap {
        //public String endpoint_x = 'http://www.payrollservers.us:8002/scci/xml/EmployeeWebInterface.asmx';
        public String endpoint_x = 'http://www.payrollservers.us/scci/xml/EmployeeWebInterface.asmx';
        
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        public mc2csComScci.AuthHeader AuthHeader;
        private String AuthHeader_hns = 'AuthHeader=https://mc2cs.com/scci';
        private String[] ns_map_type_info = new String[]{'https://mc2cs.com/scci', 'mc2csComScci'};
        public String AddEmployee(String employeeCode,String lastName,String firstName,String middleName,String designation,String title,String ssn,String dept,String location,String supervisor,String startDate,String endDate,Integer lunch,Double lunchHours,Decimal payRate0,Decimal payRate1,Decimal payRate2,Decimal payRate3,String cardnum1,String cardNum2,String cardNum3,String password,String options,String home1,String home2,String home3,String schedule,Integer exportBlock) {
            mc2csComScci.AddEmployee_element request_x = new mc2csComScci.AddEmployee_element();
            mc2csComScci.AddEmployeeResponse_element response_x;
            request_x.employeeCode = employeeCode;
            request_x.lastName = lastName;
            request_x.firstName = firstName;
            request_x.middleName = middleName;
            request_x.designation = designation;
            request_x.title = title;
            request_x.ssn = ssn;
            request_x.dept = dept;
            request_x.location = location;
            request_x.supervisor = supervisor;
            request_x.startDate = startDate;
            request_x.endDate = endDate;
            request_x.lunch = lunch;
            request_x.lunchHours = lunchHours;
            request_x.payRate0 = payRate0;
            request_x.payRate1 = payRate1;
            request_x.payRate2 = payRate2;
            request_x.payRate3 = payRate3;
            request_x.cardnum1 = cardnum1;
            request_x.cardNum2 = cardNum2;
            request_x.cardNum3 = cardNum3;
            request_x.password = password;
            request_x.options = options;
            request_x.home1 = home1;
            request_x.home2 = home2;
            request_x.home3 = home3;
            request_x.schedule = schedule;
            request_x.exportBlock = exportBlock;
            Map<String, mc2csComScci.AddEmployeeResponse_element> response_map_x = new Map<String, mc2csComScci.AddEmployeeResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'https://mc2cs.com/scci/AddEmployee',
              'https://mc2cs.com/scci',
              'AddEmployee',
              'https://mc2cs.com/scci',
              'AddEmployeeResponse',
              'mc2csComScci.AddEmployeeResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.AddEmployeeResult;
        }
    }
    public class AuthHeader {
        public String userName;
        public String password;
        public String site;
        private String[] userName_type_info = new String[]{'userName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] password_type_info = new String[]{'password','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] site_type_info = new String[]{'site','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'https://mc2cs.com/scci','true','false'};
        private String[] field_order_type_info = new String[]{'userName','password','site'};
    }
    public class AddEmployeeResponse_element {
        public String AddEmployeeResult;
        private String[] AddEmployeeResult_type_info = new String[]{'AddEmployeeResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'https://mc2cs.com/scci','true','false'};
        private String[] field_order_type_info = new String[]{'AddEmployeeResult'};
    }
}

 

Code snippet through which I am invoking the server is:

mc2csComScci m = new mc2csComScci();
mc2csComScci.AuthHeader a = new mc2csComScci.AuthHeader();
a.userName = 'testaccount';
a.password = 'password';
a.site = '1';

mc2csComScci.EmployeeWebInterfaceSoap e = new mc2csComScci.EmployeeWebInterfaceSoap();

String result = e.AddEmployee('12344','mathurtest','ptest','test','test','test','313065406','test','test','test','','',1,12,2,2,2,2,'324545','','','','','','','','',1);

system.debug('result is '+result);

 

Error received is:

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: System.Web.Services.Protocols.SoapException: Server was unable to process request. 

 

But I tried the same wsdl file with SOAP UI , it ran successfully providing desired output.

 

My instincts are that I am not setting the auth header parameters properly. But dont know for sure. If  anybody has any ideas, please help.

 

Thanks,

Pragati

 

Best Answer chosen by Admin (Salesforce Developers) 
Force.comForce.com

Hi All,

 

I fixed the header in Soap call using the following code and it worked :

 

           mc2csComScci m = new mc2csComScci();
           mc2csComScci.AuthHeader a = new mc2csComScci.AuthHeader();

           a.userName = <username>;
           a.password = <Password>;
           
           // Instantiating Inner Class to call Swipe Clock Services
           mc2csComScci.EmployeeWebInterfaceSoap e = new mc2csComScci.EmployeeWebInterfaceSoap();
           e.AuthHeader=a;

 

Thanks,

Pragati