2

I've written the following Apex class as a part of a suite of custom webservices. All have the same problem but this one is the easiest example; if I can solve it for this, I can solve it for the other webservices.

global class WebServiceA4S {
     global class returngetEnquiries {
        public String status {get;set;}
        public String error {get;set;}
        public List<Enquiry__c> results {get;set;}
    }

    Webservice static returngetEnquiries  getEnquiries() { 
        returngetEnquiries rtnError = new returngetEnquiries();
        rtnError.status='success';
        rtnError.error = '';
        rtnError.results = new List<Enquiry__c>();
        // id en name
        try {
            list<Enquiry__c> tmp = [Select id,name From Enquiry__c];
            rtnError.results = tmp;
        } 
         catch(Exception e) {
             rtnError.status='error';
             rtnError.error = String.valueof(e);

         }


     return rtnError;
        }
}

Now if I debug the rtnError returned, just before the 'return rtnError', it does show a list of Enquiries so the code works. The problem is that if I call the Webservice (via PHP or SOAPUI) the result is empty. I use the wsdl from the class, created by salesforce of course.

I also looked at the wsdl and it looks like this:

...
<xsd:complexType name="returngetEnquiries">
    <xsd:sequence/>
</xsd:complexType>
<xsd:element name="getEnquiries">
    <xsd:complexType>
      <xsd:sequence/>
    </xsd:complexType>
</xsd:element>
<xsd:element name="getEnquiriesResponse">
 <xsd:complexType>
  <xsd:sequence>
   <xsd:element name="result" type="tns:returngetEnquiries" nillable="true"/>
  </xsd:sequence>
 </xsd:complexType>
</xsd:element>
...

It looks like the returngetEnquiries is not defined. I tried to edit it and add the fields as defined in the class, but that doesn't help.

4

1 回答 1

1

After some investigating I found the solution. It is in the returnclass. The parameters should be webservice instead of public:

global class returngetEnquiries {
    webservice String status {get;set;}
    webservice String error {get;set;}
    webservice List<Enquiry__c> results {get;set;}
}
于 2012-12-04T08:37:17.670 回答