I need to migrate WCF service from .NET framework to .NET 7. I used the Microsoft upgrade assistant tool for this migration. But I am encountering compilation errors.
This is my code:
[WebInvoke(Method = "POST", UriTemplate = "UploadFotoAndroid")]
public string UploadPhotoAndroid(Stream fileContents)
{
var sFileName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + "foto.png";
EscreverNoLog("Recebendo arquivo Android - Foto");
try
{
string absFileName = string.Format("{0}\\FileUpload\\{1}"
, AppDomain.CurrentDomain.BaseDirectory
, sFileName);
EscreverNoLog("Nome do Arquivo Android - Foto: " + absFileName);
using (FileStream fs = new FileStream(absFileName, FileMode.Create))
{
fileContents.CopyTo(fs);
fileContents.Close();
}
/*
try
{
GerenciaThreadCopia thCopia = new GerenciaThreadCopia();
thCopia.ChamarThreadCopiaFoto(absFileName);
}
catch (Exception)
{
}
*/
return "$$$" + sFileName + "$$$";
}
catch (Exception ex)
{
EscreverNoLog("Erro recebimento do Arquivo Android - Foto: " + sFileName);
EscreverNoLog("Mensagem de Erro recebimento do Arquivo Android - Foto: " + ex.Message);
return "FALHA: " + ex.Message;
}
}
The errors:
The Type or namespace name 'WebInvoke' could not be found (are you missing a using directive or an assembly reference?)
The Type or namespace name 'Method' could not be found (are you missing a using directive or an assembly reference?)
Can someone please help me fixing this error?
WebInvoke. That attribute was used over 10 years ago to allow WCF to create REST services. It never caught on and became obsolete once ASP.NET MVC and Web API came out. The migration path you need is to ASP.NET Core Web API or minimal services, not CoreWCF and yes, it requires as much rewriting as it did in 2012