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
kerlvine dussoyekerlvine dussoye 

How to include username and password in external webservice callout?

Hi, 
The content of my WSDL is as such:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www........">
<soapenv:Header/>
<soapenv:Body>
<sch:InsertValueRequest>
<credential>
<userName> </userName>
<password> </password>
</credential>
<ActorVO>
    <value1> </value1>
    <value2> </value2>
    <value3> </value3>
    <value4> </value4>    
</ActorVO>
<sch:InsertValueRequest>
All the apex class was generated successfully with the WSDL. A class was created which contain the credential parameter and one which contain the values.

The problem I am facing is that when I send the request, the request is generated without the credential part, hence no request is done between the external service and salesforce. How can I modify my request being it is send?

Viewed from the debug log, i noticed the request is generated as such : 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www........">
<soapenv:Header/>
<soapenv:Body>
<sch:InsertValueRequest>
<values>
<value1> </value1>
<value2> </value2>
<value3> </value3>
<value4> </value4>
</values>
<sch:InsertValueRequest>

Below is my sample class: 

public class ActorSchema {
    public class Credential {
            public String userName;
            public String password;
            private String[] userName_type_info = new String[]{'userCode','http://.......',null,'0','1','true'};
            private String[] password_type_info = new String[]{'password','http://.....',null,'0','1','true'};        
            private String[] field_order_type_info = new String[]{'userName','password'};
        }
        
    public class ActorVO {
        public String value1;
        public String value1;
        public String value1;
        public String value1;
        private String[] apex_schema_type_info = new String[]{'http://......','false','false'};
        private String[] field_order_type_info = new String[]{'value1','value2','value3','value4'};
    }    
}


public class ActorActorimport {
    public class InsertActorResponse_element {
        public ActorSchema.ActorVO actorVO;        
        private String[] actorVO_type_info = new String[]{'actorVO','http://......',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://......','true','false'};
        private String[] field_order_type_info = new String[]{'actorVO'};
    }
    public class InsertActorRequest_element {
        public ActorSchema.ActorVO actorVO;
        private String[] actorVO_type_info = new String[]{'actorVO','http://.....',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://.....','false','false'};
        private String[] field_order_type_info = new String[]{'actorVO'};            
    }
    
    public ActorSchema.ActorVO InsertActor(ActorSchema.ActorVO actorVO) {
                ActorActorimport.InsertActorRequest_element request_x = new ActorActorimport.InsertActorRequest_element();                        
                request_x.actorVO = actorVO;           
                ActorActorimport.InsertActorResponse_element response_x;
                Map<String, ActorActorimport.InsertActorResponse_element> response_map_x = new Map<String, ActorActorimport.InsertActorResponse_element>();            
                response_map_x.put('response_x', response_x);
                WebServiceCallout.invoke(
                  this,
                  request_x,
                  response_map_x,
                  new String[]{endpoint_x, '','http://......', 'InsertActorRequest', 'http://......','InsertActorResponse','ActorActorimport.InsertActorResponse_element'}
                );
                response_x = response_map_x.get('response_x');            
                return response_x.actorVO;
            }
}

=============My Request==========
ActorActorImport.ActorImportServicePort test1 = new ActorActorImport.ActorImportServicePort();
test1.clientCert_x = ' ';
//test1.clientCertName_x = ' ';
test1.clientCertPasswd_x = ' ';
test1.endpoint_x = 'http://......';
test1.timeout_x = 50000;
 
ActorSchema.ActorVO actorVo = new ActorSchema.ActorVO();
actorVo.value1 = 'val1';
actorVo.value2 = 'val2';
actorVo.value3 = 'val3';
actorVo.value4 = 'val4';

test1.InsertActor(actorVo);

Please help!!!
EnreecoEnreeco
Hi,
You should include username/password in the body of your request.
The ActorSchema.Credential should be injected in the request but the sample class you posted doesn't provide a way to include the Credential class inside the request.
The WSDL should have generated something like:
 
public class ActorActorimport {
	//...

	public class InsertActorRequest_element {
	 	public ActorSchema.Credential credential;
	    public ActorSchema.ActorVO actorVO;
	    private String[] credential_type_info = new String[]{'credential','http://.....',null,'1','1','false'};
	    private String[] actorVO_type_info = new String[]{'actorVO','http://.....',null,'1','1','false'};
	    private String[] apex_schema_type_info = new String[]{'http://.....','false','false'};
	    private String[] field_order_type_info = new String[]{'credential','actorVO'};            
	}
	//. . .
}

But it is evidentyl missing the "credential" part.

--
May the Force.com be with you!
@enreeco
 
kerlvine dussoyekerlvine dussoye
Hello Enreeco,

I have tried that too. But unfortunately, when the request isn't generated properly as shown in the XML.
The credential part is included in the ActorVO section instead of being in the Credential section. 
It should like this: 


<credential>
<userName> </userName>
<password> </password>
</credential>
<ActorVO>
    <value1> </value1>
    <value2> </value2>
    <value3> </value3>
    <value4> </value4>    
</ActorVO>