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." }