views:

178

answers:

4

Hi.

I am trying to pass a list object of type List<UploadQueue> to a WCF SOAP method of the same parameter type and I am getting the error:

Cannot Convert from 'System.Collections.Generic.List' to 'WebAPI.Upload.UploadQueue[]'

I don't understand this because my WCF method's (below) parameter type is List<UploadQueue>:

IService.DoUpload(List<UploadQueue> request)

Here is the code that calls "DoUpload" which returns the above error.

    List<UploadQueue> results = new List<UploadQueue>();
    HttpPostedFile m_objFile  = default(HttpPostedFile);
    int m_objFlag = default(int);
    Guid m_objGuid = Guid.NewGuid();
    DateTime m_objDate = DateTime.Now;

    try
    {
        if (Request.Files.Count > 0)
        {
            for (var j = 0; i <= (Request.Files.Count - 1); j++)
            {
                m_objFile = Request.Files[j];

                if (!(m_objFile == null | string.IsNullOrEmpty(m_objFile.FileName) | m_objFile.ContentLength < 1))
                {
                    results.Add(new UploadQueue(
                        m_objGuid,
                        m_objFlag,
                        m_objFile.ContentLength,
                        m_objFile.FileName,
                        m_objDate)
                    );

                }

            }
        }

    }
    catch (Exception ex)
    {
        //handle error
    }

    retParam = upload.DoUpload(results);

Ideas? Thanks.

+1  A: 

Try doing results.ToArray(). That will probably fix it.

upload.DoUpload(results.ToArray());

The problem is that the soap service says that it wants an array of objects, and not a list. When the proxy class is built from the WSDL, it converts it to the most basic object it can that satisfies the needs of the service which is an array.

Kevin
+1  A: 
retParam = upload.DoUpload(results.ToArray());

...or similar.

Justin Niessner
+3  A: 

The generated client has replaced the List with an Array (The default behaviour). With VS.NET 2008 you have the option of generating this with a List instead- look at the Configure Service Dialog Box. As other have said ToArray will work.

RichardOD
+11  A: 
awhite
Nice one. Thanks.
Code Sherpa
You're welcome. It took me a while to figure it out, too.
awhite