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
rv90rv90 

How can a salesforce WSDL file to authenticate without session id from external application ?

Hi i got a custom WSDL file and when ever i try to request data from salesforce from external application through wsdl it is asking me session id , Is there any way where i can access the salesforce data through wsdl file with out entering session id each and every time or like anything where we can include authentication in the same apex class and then generate the wsdl file where the authentication will take pace internally or something like that.
Best Answer chosen by rv90
James LoghryJames Loghry
To put it simply, every time you call a soap service (other than logging in or logging out), you need a session id.  There is no automatic way of grabbing that session id other than logging into salesforce with a username / password and likely security token.

However, what I typically do is try to persist that session id in my application.  For instance, you cache it somewhere in your external service so that you only call login once, and then you can pass the same session id until that session expires.

Once the session expires, then you'll get an error message and can re-call the login service and re-cache the session id if necessary. 

All Answers

James LoghryJames Loghry
Hi Ravitej,

You'll need to call the login operation first prior to passing in the session Id.  The login operation can be found by downloading (and importing) the enterprise WSDL file first.  Once you call the login operation, you'll get the session id in the response, and then you can pass that session id into your custom wsdl / web service call.

It's best to test this in soap ui first, to make sure you have the general flow down.  Patrick Connelly has done a great job of explaining this in one of his many blog posts here: http://blog.deadlypenguin.com/blog/2012/02/03/salesforce-and-soapui/

Regards,
- James
rv90rv90
request from external application using WSDL file

I am here sending a request from external application using  Noble Phone number as a parameter and generating session id each and every time i want to call salesforce. 

Is there any was where this authentication is done automatcally, so that we do not need to generate session id everytime for salesforce call. ?

Any method where we can pass username and -password and token key in the apex class itself so that we just need to send username and password and the parameters to get the response from the saleforce?

Please suggest if any solution. I have my apex code snippet for WSDL SOAP webservice for  reference

Apex code for WSDL file SAOP webservice

 
James LoghryJames Loghry
To put it simply, every time you call a soap service (other than logging in or logging out), you need a session id.  There is no automatic way of grabbing that session id other than logging into salesforce with a username / password and likely security token.

However, what I typically do is try to persist that session id in my application.  For instance, you cache it somewhere in your external service so that you only call login once, and then you can pass the same session id until that session expires.

Once the session expires, then you'll get an error message and can re-call the login service and re-cache the session id if necessary. 
This was selected as the best answer
rv90rv90
Thanks james :)