I´m new to asp.net core, and I´m having trouble with injections on a web service.
namespace Web.WebServices
{
public class InstallService : IService
{
private SQLContext _context;
public InstallService(SQLContext context)
{
_context = context;
}
public string Fcn(string msg)
{
//Just for testing, the rest of the code is not altering the results
return string.Join(string.Empty, msg.Reverse());
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
string Fcn(string msg);
}
}
This is the ConfigureService method:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton(Configuration);
services.AddDbContext<SQLContext>(options => options.UseSqlServer(Configuration.GetConnectionString("SQLConnection")));
services.AddSoapExceptionTransformer((ex) => ex.Message);
services.AddScoped<IService, InstallService>();
}
And the configure method:
app.UseSoapEndpoint<InstallService>("/ServicePath.asmx", new BasicHttpBinding());
Now the problem, when I try to consume the webservice I get the error:
"System.ServiceModel.FaultException. Non-static method requires a target"
And if I remove the injection the webservice works fine.
namespace Web.WebServices
{
public class InstallService : IService
{
public string Fcn(string msg)
{
return string.Join(string.Empty, msg.Reverse());
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
string Fcn(string msg);
}
}
And the Configure service method:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSingleton(Configuration);
services.AddDbContext<SQLContext>(options => options.UseSqlServer(Configuration.GetConnectionString("SQLConnection")));
services.AddSoapExceptionTransformer((ex) => ex.Message);
services.AddScoped(new InstallService());
}
But I need to use the webService to save data to the SQL Server.
I´m almost sure something wrong is not right, but I can´t figure it out.