+ Start a Discussion
NamrapNamrap 

Need Help with callout to external web service

I need some help. I can not get salesforce to access an external web service.  I have added the endpoint thru Remote Site Settings and generated the APEX Classes from the wsdl using wsdl2apex.  I have added a button to the opportunity to activate the web service.  When I press the button I get the following error.

 

A problem with the OnClick JavaScript for this button or link was encountered:

 

{faultcode:'soapenv:Client', faultstring:'No operation available for request {http://soap.sforce.com/schemas/package/agilewebservices}AgileWebservices.AddFolder, please check the WSDL for the service.',}

 

What am I missing?  I can access the webservice internally using soapUI 3.6 so I know the service works.

  

Here is the generated Apex Class:

 

//Generated by wsdl2apex

public class agilewebservices {
    public class x_E_S_01843S_ServicesSOAPSOAP11Document_E_S_01843S_Services {
        public String endpoint_x = 'https://websvcs01.test1.embarq.com:443/E/S/01843S/Services';
        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://AgileWebservices', 'agilewebservices', 'http://AgileWebservices/AbstractTypes', 'agilewebservicesAbstracttypes'};
        public agilewebservices.LLDocument AddFolder(String user_x,String password,String folderName,Integer objectid) {
            agilewebservices.AddFolder_element request_x = new agilewebservices.AddFolder_element();
            agilewebservices.AddFolderResponse_element response_x;
            request_x.user_x = user_x;
            request_x.password = password;
            request_x.folderName = folderName;
            request_x.objectid = objectid;
            Map<String, agilewebservices.AddFolderResponse_element> response_map_x = new Map<String, agilewebservices.AddFolderResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://AgileWebservices/AddFolder',
              'http://AgileWebservices',
              'AddFolder',
              'http://AgileWebservices',
              'AddFolderResponse',
              'agilewebservices.AddFolderResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.AddFolderResult;
        }
    }
    public class LLDocument {
        public String DocumentName;
        public Integer ObjectID;
        private String[] DocumentName_type_info = new String[]{'DocumentName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] ObjectID_type_info = new String[]{'ObjectID','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://AgileWebservices','true','false'};
        private String[] field_order_type_info = new String[]{'DocumentName','ObjectID'};
    }
    public class AddFolderResponse_element {
        public agilewebservices.LLDocument AddFolderResult;
        private String[] AddFolderResult_type_info = new String[]{'AddFolderResult','http://AgileWebservices','LLDocument','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://AgileWebservices','true','false'};
        private String[] field_order_type_info = new String[]{'AddFolderResult'};
    }
    public class AddFolder_element {
        public String user_x;
        public String password;
        public String folderName;
        public Integer objectid;
        private String[] user_x_type_info = new String[]{'user','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] password_type_info = new String[]{'password','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] folderName_type_info = new String[]{'folderName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] objectid_type_info = new String[]{'objectid','http://www.w3.org/2001/XMLSchema','int','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://AgileWebservices','true','false'};
        private String[] field_order_type_info = new String[]{'user_x','password','folderName','objectid'};
    }
}

 

Here is the button code:

 

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var myvar = sforce.apex.execute("agilewebservices","AgileWebservices.AddFolder", {user_x:"lapispw",password:"lapispw",folderName:"Mikes Third Test - 00000003",objectid:25953});
window.alert(myvar);

 

SvenSven

Hi 

 

i think this just means that the addFolder element is not found

instead of AgileWebservices.AddFolder try AddFolder.

 

I to test it i would try to call it from an apex class first and then if you know it works call that apex class in your javascript statement.

NamrapNamrap

I changed my code and I am getting the following XML returned;

<soap:Envelope xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/ xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <soap:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <AddFolderResponse xmlns="http://AgileWebservices">

         <AddFolderResult>

            <ObjectID>109614</ObjectID>

         </AddFolderResult>

      </AddFolderResponse>

   </soap:Body>

</soap:Envelope>

 

now when I try to parse the xml to get the ObjectID value all I get is blanks.  Here is my code:

 

          HTTPResponse res = http.send(req);
          Dom.Document doc = res.getBodyDocument();
          String soapNS = 'http://schemas.xmlsoap.org/soap/envelope/';
          for(dom.XmlNode node : doc.getRootElement().getChildElements()) {
             if(node.getName()== 'AddFolderResult') {
                xObjectID = node.getChildElement('ObjectID', soapNS).getText();
             }
          }

SvenSven

Hi

 

There is a good document of the dom.document use

 

Dom.Document doc = res.getBodyDocument();
        
        //Retrieve the root element for this document. 
    
        Dom.XMLNode address = doc.getRootElement();
        
        String name = address.getChildElement('name', null).getText();
        String state = address.getChildElement('state', null).getText();
        // print out specific elements 
    
        System.debug('Name: ' + name);
        System.debug('State: ' + state);
        
        // Alternatively, loop through the child elements. 
    
        // This prints out all the elements of the address 
    
        for(Dom.XMLNode child : address.getChildElements()) {
           System.debug(child.getText());
        }

 or you can also use the XmlStreamReader class to loop your elements like this

 

 XmlStreamReader reader = res.getXmlStreamReader();
          System.debug(reader);
          while(reader.hasNext()) {
      		System.debug('Event Type:' + reader.getEventType());
     		 if (reader.getEventType() == XmlTag.START_ELEMENT) {
        		System.debug(reader.getLocalName());
        		
      		}
      		reader.next();
    	}

 

NamrapNamrap

I have tried the code and I receive an error.  I even replaced the null with http://schemas.xmlsoap.org/soap/envelope/ and still get the same error.

 

code

 

Dom.XMLNode address = doc.getRootElement();
String name = address.getChildElement('ObjectID', null).getText();

error

 

Attempt to de-reference a Null object