[SalesForce] Calling an ASP.NET SOAP service and passing a List<> of custom objects

I created the APEX class from the WSDL of an ASP.NET asmx service, this now gives me access to the types and methods provided by my service.

One of the methods takes in a List of objects described by the method: (ex: ASP.NET method)

[XmlInclude(typeof(List))]
[WebMethod(Description = "Consumes a list of changes from Salesforce.")]
        public void NotifyChanges(List<SalesforceChangeType> changes)
        {
            foreach (var changeType in changes)
            {
                log.Info(string.Format("Type:{0}, Id:{1}", changeType.ChangeType, changeType.EntityId));
            }
        }

I am trying to call this web service but when the APEX class was generated it created a type of ArrayOfSalesforceChangeType which is also the argument for the method.

TriggerService.SalesforceChangeType change = new TriggerService.SalesforceChangeType();

TriggerService.ArrayOfSalesforceChangeType changes = new TriggerService.ArrayOfSalesforceChangeType();

TriggerService.TriggerServiceSoap svc = new TriggerService.TriggerServiceSoap();

changes.add(change) <-- doesn't work, reports "Method doesn't exist or incorrect signature" 

// changes[0] = change; <-- doesn't work either "Expression must be a list type: Service.ArrayofSalesforceChangeType"

svc.NotifyChanges(changes);

So my question is how do I add items to a custom List that was generated from the APEX generated WSDL..

Hope this makes sense to someone..

Thanks

Best Answer

The apex class for ArrayOfSalesforceChangeType will appear something like:

public class ArrayOfSalesforceChangeType {
    public ApexClassForWSDL.SalesforceChangeType[] SalesforceChangeType;
    private String[] SalesforceChangeType_type_info = new String[]{'SalesforceChangeType','http://webservice/api','SalesforceChangeType','0','-1','true'};
    private String[] apex_schema_type_info = new String[]{'http://webservice/api','true','false'};
    private String[] field_order_type_info = new String[]{'SalesforceChangeType'};
}

You will need to add the records to the SalesforceChangeType member.

E.g.

TriggerService.ArrayOfSalesforceChangeType changes = new TriggerService.ArrayOfSalesforceChangeType();
TriggerService.SalesforceChangeType change = new TriggerService.SalesforceChangeType();
changes.SalesforceChangeType = new List<SalesforceChangeType>();
changes.SalesforceChangeType.add(change);
Related Topic