1

I have a window service that is password protected.I have generate Apex class from that window service WSDL.Now i am try to call the service using stub method its shows me a error message"IO ExCeption : External server did not return any content." because i think this window service is password protected whose username :"abc",Password :"password".so how i can make apex call using the credential?Where i will define username and password in stub.Code is given as follows ::

APEX CLASS GENERATED FROM APEX ::

    public class wwwMaterialiseBeErp 
    {    
      public class BasicHttpBinding_IExternalService 
      {

        public String endpoint_x = 'https://fathomcs.com/Streamics-test/External.svc';
        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[]{'http://www.materialise.be/eRP','wwwMaterialiseBeErp','http://schemas.microsoft.com/2003/10/Serialization/','schemasMicrosoftCom200310Serializat','http://schemas.datacontract.org/2004/07/eRP.ExternalService.Model','schemasDatacontractOrg200407ErpExte','http://schemas.datacontract.org/2004/07/eRP.ExternalService.Model.Base','schemasDatacontractOrg200407ErpExte1','http://schemas.microsoft.com/2003/10/Serialization/Arrays','schemasMicrosoftCom200310Serializat1','http://schemas.datacontract.org/2004/07/Materialise.eRP.Entities','schemasDatacontractOrg200407Materia'};

        public Integer GetQuotesByContactPersonCount(String contactPersonExternalId) {
            wwwMaterialiseBeErp.GetQuotesByContactPersonCount_element request_x = new wwwMaterialiseBeErp.GetQuotesByContactPersonCount_element();
            wwwMaterialiseBeErp.GetQuotesByContactPersonCountResponse_element response_x;
            request_x.contactPersonExternalId = contactPersonExternalId;
            Map<String, wwwMaterialiseBeErp.GetQuotesByContactPersonCountResponse_element> response_map_x = new Map<String, wwwMaterialiseBeErp.GetQuotesByContactPersonCountResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
                this,
                request_x,
                response_map_x,
                new String[]{endpoint_x,
                'http://www.materialise.be/eRP/IQuoteService/GetQuotesByContactPersonCount',
                'http://www.materialise.be/eRP',
                'GetQuotesByContactPersonCount',
                'http://www.materialise.be/eRP',
                'GetQuotesByContactPersonCountResponse',
                'wwwMaterialiseBeErp.GetQuotesByContactPersonCountResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetQuotesByContactPersonCountResult;
        }
    }
    public class GetQuotesByContactPersonCount_element {
        public String contactPersonExternalId;
        private String[] contactPersonExternalId_type_info = new String[]{'contactPersonExternalId','http://www.materialise.be/eRP','string','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://www.materialise.be/eRP','true','false'};
        private String[] field_order_type_info = new String[]{'contactPersonExternalId'};
    }
    public class GetQuotesByContactPersonCountResponse_element {
        public Integer GetQuotesByContactPersonCountResult;
        private String[] GetQuotesByContactPersonCountResult_type_info = new String[]{'GetQuotesByContactPersonCountResult','http://www.materialise.be/eRP','int','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.materialise.be/eRP','true','false'};
        private String[] field_order_type_info = new String[]{'GetQuotesByContactPersonCountResult'};

}





And HERE IS THE STUB CLASS USED IN VFPAGES ::


public with sharing class WebserviceCall 

{

 public Double message {get; private set;}

  public PageReference hello() 

  {    

    wwwMaterialiseBeErp.BasicHttpBinding_IExternalService stub = new    wwwMaterialiseBeErp.BasicHttpBinding_IExternalService();
   // stub.clientCertName_x='';

    stub.clientCert_x='fathomcs';
    stub.clientCertPasswd_x='test';
    stub.timeout_x=60000;

    // Make the Web service call
    message = stub.GetQuotesByContactPersonCount('1213233');
    return null;
    }

}
2

Assuming the problem is authentication, you will need to check with the service provider what authentication mechanism they will accept.

One common one is basic access authentication (which is secure providing HTTPS is used as it appears to be). As this Apex Web Services and Callouts documentation explains, including this in the request can be as simple as just adding a header (with the below code assuming you have chosen to keep the username and password in a custom setting):

MyCustomSetting__c s = MyCustomSetting__c.getInstance()
String v = EncodingUtil.base64Encode(Blob.valueOf(s.UserName__c + ':' + s.Password__c));
stub.inputHttpHeaders_x.put('Authorization', 'Basic ' + v);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.