locked
Can not passing image as argument RRS feed

  • Question

  • Hi friends...I want making a web service through asp.net web service (ASMX) but i can not passing image as argument.

    my code is : 

    [WebMethod] public bool insertUser(string name, string userName, string psw, string bio, Image img) { Tbl_users tblUser = new Tbl_users(); Database db = new Database(); try { tblUser.Name = name; tblUser.Username = userName; tblUser.Psw = psw; tblUser.Bio = bio; string path = System.IO.Path.Combine(Server.MapPath(@"~/Content/images/Users/")); if (img != null) { string PicName = name + ".jpeg"; img.Save(path + PicName); tblUser.Image = PicName; db.Tbl_users.Add(tblUser); if (db.SaveChanges() > 0) { return true; }

    .

    .

    . } } }

    my code at application :

      Image img = Image.FromFile(openFileDialog1.FileName);
    
       webservice.insertUser(txtName.Text, txtUserName.Text, txtPsw.Text, txtBio.Text,img);

    When i calling this method in my application it say,can not convert image to myApp.webservice.imge.

    why did this error occurred? (just for image data type not for string !).

    What is the best solution?

    Please help me.

    thank you so much.

    • Moved by CoolDadTx Monday, February 5, 2018 3:52 PM ASP.NET related
    Sunday, February 4, 2018 6:19 PM

All replies

  • For the best support go here. Also mention the exact error.

    https://forums.asp.net/


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Sunday, February 4, 2018 6:58 PM
  • Hi Arash_,

    According to your question is more related to ASP.Net, you could repost a new thread Asp.Net forum  for suitable support.

    If you have some grammar or code errors in using C#, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 5, 2018 8:59 AM
  • Not so strange because an image is just an array of bytes. You can serialize it to XML to get this gone. 

    But as the others advice you to look for it in the Asp.net forums, focus you on that. 


    Success Cor

    Monday, February 5, 2018 9:26 AM