0

I want to create a web service to upload txt files and store them, this is my service:

[WebMethod]
    public bool SaveFiles(HttpPostedFileBase[] files)
    {
        try
        {

            foreach (HttpPostedFileBase file in files)
            {
                var InputFileName = Path.GetFileName(file.FileName);
                var ServerPath = Path.Combine(string.Format("{0}{1}"), "UploadedFiles", InputFileName);

                file.SaveAs(ServerPath);
            }
            return true;
        }
        catch (Exception ex)
        {

        }
        return true;
    }

and on the client side, who is consuming the service I have in my controller

 [HttpPost]
    public ActionResult Upload(HttpPostedFileBase[] files)
    {
        ViewBag.status = "";

        if (ModelState.IsValid)
        {
            ReferenciaMiServicio.MiServicioSoapClient service = new ReferenciaMiServicio.MiServicioSoapClient();
            var response = service.SaveFiles(files);
            // Falta mandar a¡error cuando la carga no fue valida
            ViewBag.status = "Archivos cargados satisfactoriamente";

        }

        return View();
    }

But I get this error in the controller:

ErrorCS1503 Argumento 1: Cannot convert from 'System.Web.HttpPostedFileBase[]' a 'PruebaMiServicio.ReferenciaMiServicio.HttpPostedFileBase[]'

and exactly highlights the error in files

var response = service.SaveFiles(files);

You could help me with the solution, this is all C# asp.net

Thank you!

Roman Patutin
  • 2,171
  • 4
  • 23
  • 27
  • Looks like, you're getting your project's namespace, which means the datatype `System.Web.HttpPostedFileBase[]` is not getting resolved in the client side, make sure you include `using System.Web;` in client side – kowsikbabu Mar 13 '19 at 06:18
  • I'd do something like https://stackoverflow.com/questions/16906711/httpclient-how-to-upload-multiple-files-at-once rather than trying to call it through generated proxy classes... – Alexei Levenkov Mar 13 '19 at 06:21
  • I am using these: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; But it's still the same mistake. – Daniel Echeverry Mar 13 '19 at 06:48

0 Answers0