1

I have a .NET Core 2.0 web app that needs to access a web service via WCF reference.

The problem is that the WCF reference it's not working with .NET Core. So, I created a .NET Framework console app to add the WCF reference. I added the console app inside the solution with .NET Core 2.0 web app.

When I set the console app as the startup project and run it, the web service return the desired value. Working perfect.

So, I added the console app reference to the .NET Core web app and tried to call the same method. Not working.

This is the method that calls the WCF web service method in my console app:

public static string GetToken()
{
    try
    {
        var client = new service.CFCGateway();

        var credential = new service.validaUsuarioExternoEnvDTO();
        credential.login = "xxxxxxx";
        credential.senha = "xxxxxxx";

        var result = client.validaUsuarioExterno(credential);

        return result.passaporte;
    }
    catch (Exception ex)
    {
        return null;
    }
}

And this is what I'm doing to call the console app method:

string token = consoleapp.Services.GetToken();

Checking with breakpoint, when the code reaches this line:

 var client = new service.CFCGateway();

I'm receiving this error:

Object reference not set to an instance of an object.
at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
   at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()

Any ideas what I am doing wrong?

gregoryp
  • 920
  • 4
  • 15
  • 35

0 Answers0