views:

188

answers:

1

I have a web service that looks like this

    [WebMethod]
    public int Import(System.Collections.Generic.List<Record> importRecords)
    {
        int count = 0;
        if (importRecords != null && importRecords.Count > 1)
        {
            DataLayer datalayer = new DataLayer();
            foreach (Record brec in importRecords)
                if (rec != null) 
                {
                    datalayer.InsertUpdateRecord(rec);
                    count++;
                }
        }
        return count;
    }

And i have a client software that wants to send data to the web service using this method

 ImportService.BVRImportService importService = new ImportService.ImportService();
 ImportService.Record myRecord = new ImportService.Record();
 myRecord.FirstName = "Adam";
 System.Collections.Generic.List<ImportService.Record> myRecords = 
     new List<ImportService.Record>();
 myRecords.Add(myRecord);
 importService.ImportData(myRecords);

I keep getting this message when I try to compile the client software.

    Error   1 The best overloaded method match for 'ImportTask.ImportService.ImportService.ImportData(ImportTask.ImportService.Record[])' has some invalid arguments
Error   2 Argument '1': cannot convert from 'System.Collections.Generic.List<ImportTask.ImportService.Record>' to 'ImportTask.ImportService.BVRRecord[]'

Does anyone know what i'm doing wrong?

+2  A: 

It looks like the reference the client has contains an Record[] instead of a List<Record>. You can fix this by calling the .ToArray method on the List<Record>.

importService.ImportData(myRecords.ToArray());

I'm also confused by the use of Record in code but BVRRecord in the error messages. Are you changing the type names in your solution or are there actually 2 different types? If it's the latter you'll also need to convert to the BVRRecord type before calling ImportData.

JaredPar
thanks this worked.
zSysop
i copied that error message before i changed it the object to Record. it still did the same thing. But your solution solved the error.
zSysop
You can also fix this by clicking the "Advanced" button on the "Add Service Reference" dialog and setting to use Generic List for collections instead of array.
John Saunders