1

I want to build a simple .NET web service to upload Image file. I want use image with Base64, so for this, I have write this code but it is not correct.

[Route("SaveDocument")]
[WebMethod]
public bool SaveDocument(Byte[] docbinaryarray,string docname)
{
    string strdocPath;
    strdocPath = "C:\\DocumentDirectory\\" + docname;
    FileStream objfilestream = new FileStream(strdocPath, FileMode.Create, FileAccess.ReadWrite);
    objfilestream.Write(docbinaryarray, 0, docbinaryarray.Length);
    objfilestream.Close();

    return true;
}

If I try to run my web service, it start, but if I try to use POSTMAN to call it, I receive error.

I call Web Service in this mode:

http://localhost:55649/SaveDocument

The error is Eorr 500

EDIT I have change my code to this:

[Route("SaveDocument")]
[HttpPost]
public bool SaveDocument(Byte[] docbinaryarray, string docname)
{
    string strdocPath;
    strdocPath = "C:\\DocumentDirectory\\" + docname;
    FileStream objfilestream = new FileStream(strdocPath, FileMode.Create, FileAccess.ReadWrite);
    objfilestream.Write(docbinaryarray, 0, docbinaryarray.Length);
    objfilestream.Close();

    return true;
}

Now I can call the Web Service, to do this, I use PostMan, I insert this link:

http://localhost:55649/api/SaveDocument

In the body part I select Image file. So if I try to call this link, I have this error:

ERROR { "Message": "No HTTP resource was found that matches the request URI 'http://localhost:55649/api/SaveDocument'.", "MessageDetail": "No action was found on the controller 'Omniacare' that matches the request." }

bircastri
  • 2,169
  • 13
  • 50
  • 119
  • Check your Application Event Log for error details. Most likely your IIS ApplicationPool user does not have privileges to write to C:\DocumentDirectory. – Filburt Oct 27 '15 at 10:10
  • I have the privileges to write under C:\, and another point is, I have insert a break point at the first line of my method, and I'm not able to do debub because I receive error – bircastri Oct 27 '15 at 10:23
  • Well what does the Application Event Log say? A server side 500 error of an asp.net webservice should show up there giving you a stacktrace containing more details. – Filburt Oct 27 '15 at 10:35
  • Possible duplicate of [How To Accept a File POST - ASP.Net MVC 4 WebAPI](http://stackoverflow.com/questions/10320232/how-to-accept-a-file-post-asp-net-mvc-4-webapi) – pask23 Oct 27 '15 at 15:16

0 Answers0