0

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?

3
  • 1
    This isn't about WCF at all. WCF SOAP services never used 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 Commented Jan 24, 2024 at 15:22
  • You used the upgrade assistant to just upgrade the version, but the code in it didn't change. WebInvokeThis method does not work with .NET 7. WebInvokeAttribute Class Commented Jan 25, 2024 at 6:16
  • You can use [HttpPost("UploadFotoAndroid")]. But I think the rest of your code needs to be changed. WCF migration is more than just an upgrade. Commented Jan 25, 2024 at 6:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.