4

I have read through the apex developer's guide - webservice section three times but got more confused. Based on my previous knowledge, invoking a Soap webservice should be something like sending an xml request(post) to a wsdl server and get the xml response. So is there any place I can test invoking it that way? Workbench is majorly for Rest service and I have tried SoapUI but got some errors. So is there any way to invoke a Soap wsdl without using AJAX? Simple as the following code:

global class myClass { 
  webService static Id makeContact(String lastName, Account a) { 
        Contact c = new Contact(LastName = lastName, AccountId = a.Id); 
        return c.id; 
    }
}
  • I've used SoapUI for SOAP before. What are the errors? – Boris Bachovski Jun 23 '14 at 6:03
  • The error is: Error loading [ap1.salesforce.com/services/wsdl/class/MyWebService?wsdl]: org.apache.xmlbeans.XmlException: org.apache.xmlbeans.XmlException: error: Unexpected character encountered (lex state 3): '&' – Lance Shi Jun 23 '14 at 6:04
  • @LanceShi: Try to clear all proxy settings and uncheck Add Authentication. I haven't had this error but i found the solution in a blog. – varun guruvugari Jun 23 '14 at 6:14
  • @varunguruvugari: Do you mean clear the proxy settings in my browser or Soap UI? – Lance Shi Jun 23 '14 at 6:19
  • 1
    try downloading the wsdl before loading it into SOAPUI, i've seen some differences similar with your error message. – Samuel De Rycke Jun 23 '14 at 6:57
2

I had to modify your webservice a bit to get a valid WSDL that SOAPUI could import. When you pass the accountId as the Account type Salesforce adds a whole lot of extra simple and complex types to the WSDL that aren't really needed. The WSDL goes from 6 KB to 542 KB. By sticking with strings or Ids the WSDL is much simpler.

Without any modifications I get the following error from SoupUI:

Error: type 'address@http://soup.sforce.com/schemas/class/DFB/myClass'

This is because there is no complex or simple type address in namespace http://soap.sforce.com/schemas/class/DFB/myClass (alias tns).

Here is my simplified Apex web service:

global class myClass { 
    webService static Id makeContact(String lastName, Id accountId) { 
        Contact c = new Contact(LastName = lastName, AccountId = accountId); 
        insert c;
        System.debug(LoggingLevel.Info, 'Created ' + c.Id + ' for ' + accountId);
        return c.id; 
    }
}

Be sure to save the WSDL directly from the link rather than opening it in the browser and then saving it to disk. I've found browsers can make subtle changes to the WSDL that will sometimes corrupt them.

Saving WSDL directly from link

The resulting WSDL imported into SoupUI successfully for me and I was able to make the following request. Here the SessionID was pulled from an active session using the anonymous apex:

String sessionID = UserInfo.getSessionId();
System.debug(sessionID);

Sample request to same pod as the session was retrieved from:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:myc="http://soap.sforce.com/schemas/class/DFB/myClass">
   <soapenv:Header>
      <myc:SessionHeader>
         <myc:sessionId>00D700000000001!AQoAQGOTA_NOTAREALSESSIONID_Bqf78awnl</myc:sessionId>
      </myc:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <myc:makeContact>
         <myc:lastName>Foo</myc:lastName>
         <myc:accountId>0017000000UolWs</myc:accountId>
      </myc:makeContact>
   </soapenv:Body>
</soapenv:Envelope>

Which gave the response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/schemas/class/DFB/myClass">
   <soapenv:Body>
      <makeContactResponse>
         <result>003700000000005AAP</result>
      </makeContactResponse>
   </soapenv:Body>
</soapenv:Envelope>
1

This error simply means that the XML document you're receiving is not well-formed (the & character needs to be escaped as &). Nothing to do except fix the document. Please post the WSDL file here.

http://xmlbeans.996285.n3.nabble.com/RE-XMLBeans-error-td6477.html

  • Is there anything related to proxy settings, etc.? I just copied the simple code from apex developer guide and generated wsdl file with that so it should be an issue of the wsdl... – Lance Shi Jun 23 '14 at 6:38
0

Salesforce also has a reference document called Sample SOAP Messages that I have found to be a useful resource.

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.