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
Saniya Khan 2Saniya Khan 2 

Soap Credential in apex callouts

Hi All,
I generated the apex classes from wsdl but didn't know how to specify credential.
here is code for that 
public class Revenue_Management {
        public String endpoint_x = 'Revenue_Management';
        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;
        private String[] ns_map_type_info = new String[]{'urn:com.workday/bsvc','comWorkdayBsvc'};

        public comWorkdayBsvc.Cash_SaleObjectType Cancel_Cash_Sale(comWorkdayBsvc.Cash_SaleObjectType Cash_Sale_Reference) {
            comWorkdayBsvc.Cancel_Cash_Sale_RequestType request_x = new comWorkdayBsvc.Cancel_Cash_Sale_RequestType();
            comWorkdayBsvc.Cancel_Cash_Sale_ResponseType response_x;
            request_x.Cash_Sale_Reference = Cash_Sale_Reference;
            Map<String, comWorkdayBsvc.Cancel_Cash_Sale_ResponseType> response_map_x = new Map<String, comWorkdayBsvc.Cancel_Cash_Sale_ResponseType>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
                this,
                request_x,
                response_map_x,
                new String[]{endpoint_x,
                '',
                'urn:com.workday/bsvc',
                'Cancel_Cash_Sale_Request',
                'urn:com.workday/bsvc',
                'Cancel_Cash_Sale_Response',
                'comWorkdayBsvc.Cancel_Cash_Sale_ResponseType'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.Cash_Sale_Reference;
        }

It will will be grat if anyone will help me.

Many Thanks,
Saniya
Raj VakatiRaj Vakati
Try something like below.. you need to change the code based on how your WSDL is designed to accept  the values
 
public class Revenue_Management {
        public String endpoint_x = 'Revenue_Management';
        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;
        private String[] ns_map_type_info = new String[]{'urn:com.workday/bsvc','comWorkdayBsvc'};

        public comWorkdayBsvc.Cash_SaleObjectType Cancel_Cash_Sale(comWorkdayBsvc.Cash_SaleObjectType Cash_Sale_Reference) {
            comWorkdayBsvc.Cancel_Cash_Sale_RequestType request_x = new comWorkdayBsvc.Cancel_Cash_Sale_RequestType();
            comWorkdayBsvc.Cancel_Cash_Sale_ResponseType response_x;
			
			
			Blob headerValue = Blob.valueOf('LOGIN' + ':' + 'LOGINPWD');
        String authorizationHeader = 'Basic ' +EncodingUtil.base64Encode(headerValue);
            String sURL = 'https:/testURL';
            System.debug('***authorizationHeader***'+authorizationHeader);
            response_x.inputHttpHeaders_x = new Map<String,String>();
            response_x.inputHttpHeaders_x.put('URL',sURL);        
            response_x.inputHttpHeaders_x.put('Authorization',authorizationHeader);
			
			
			
            request_x.Cash_Sale_Reference = Cash_Sale_Reference;
            Map<String, comWorkdayBsvc.Cancel_Cash_Sale_ResponseType> response_map_x = new Map<String, comWorkdayBsvc.Cancel_Cash_Sale_ResponseType>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
                this,
                request_x,
                response_map_x,
                new String[]{endpoint_x,
                '',
                'urn:com.workday/bsvc',
                'Cancel_Cash_Sale_Request',
                'urn:com.workday/bsvc',
                'Cancel_Cash_Sale_Response',
                'comWorkdayBsvc.Cancel_Cash_Sale_ResponseType'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.Cash_Sale_Reference;
        }

 
Saniya Khan 2Saniya Khan 2
Hi Raj,
Thanks for your reply.
just have one query why you are using  response_x not request_x for  response_x.inputHttpHeaders_x?

Many thanks.
Saniya
Raj VakatiRaj Vakati
My mistake .. you are correct its must be request_x  ... ( Again i can suggest to check with the wsdl ) what is the value you need to pass 
Saniya Khan 2Saniya Khan 2
Raj
Its not working