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
sivaextsivaext 

delegated authentication for between two salesforce orgs

hi,
We have two orgs , one org has enabled DA(delegated authentication). followed below steps to connect from one org to another org
1. Enabled DA
2. Downloaded DA wsdl 
3. enabled single sign on permission to one of the user 
4. added default gateway URL 
5. WSDL parsed into other salesforce org
class:
//Generated by wsdl2apex

public class authenticationSoapSforceCom {
    public class AuthenticateResult {
        public Boolean Authenticated;
        private String[] Authenticated_type_info = new String[]{'Authenticated','urn:authentication.soap.sforce.com',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:authentication.soap.sforce.com','true','false'};
        private String[] field_order_type_info = new String[]{'Authenticated'};
    }
    public class Authenticate {
        public String username;
        public String password;
        public String sourceIp;
        private String[] username_type_info = new String[]{'username','urn:authentication.soap.sforce.com',null,'1','1','false'};
        private String[] password_type_info = new String[]{'password','urn:authentication.soap.sforce.com',null,'1','1','false'};
        private String[] sourceIp_type_info = new String[]{'sourceIp','urn:authentication.soap.sforce.com',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:authentication.soap.sforce.com','true','false'};
        private String[] field_order_type_info = new String[]{'username','password','sourceIp'};
    }
    public class AuthenticationService {
        public String endpoint_x = 'https://test.salesforce.com';
        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:authentication.soap.sforce.com', 'authenticationSoapSforceCom'};
        public Boolean Authenticate(String username,String password,String sourceIp) {
            authenticationSoapSforceCom.Authenticate request_x = new authenticationSoapSforceCom.Authenticate();
            request_x.username = username;
            request_x.password = password;
            request_x.sourceIp = sourceIp;
            authenticationSoapSforceCom.AuthenticateResult response_x;
            Map<String, authenticationSoapSforceCom.AuthenticateResult> response_map_x = new Map<String, authenticationSoapSforceCom.AuthenticateResult>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'urn:authentication.soap.sforce.com',
              'Authenticate',
              'urn:authentication.soap.sforce.com',
              'AuthenticateResult',
              'authenticationSoapSforceCom.AuthenticateResult'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.Authenticated;
        }
    }
}

testing with developer console

authenticationSoapSforceCom.AuthenticationService   Stub = new authenticationSoapSforceCom.AuthenticationService ();

Stub.Authenticate('test@gmail.com','password','0.0.0.0');

Getting below error:
System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found 'http://www.w3.org/1999/xhtml:html'

Please help to resolve this issue

Thanks 
SIva.
ShashankShashank (Salesforce Developers) 
It could most probably be a firewall/whitelisting issue. If you are still facing this issue, please ensure you whitelist all salesforce IPs as per this article: https://help.salesforce.com/HTViewSolution?id=000003652&language=en_US