C# ASP.NET核心Web服务

C# ASP.NET核心Web服务,c#,web-services,asp.net-core,C#,Web Services,Asp.net Core,我是asp.net核心的新手,在web服务的注入方面遇到了麻烦 namespace Web.WebServices { public class InstallService : IService { private SQLContext _context; public InstallService(SQLContext context) { _context = context; }

我是asp.net核心的新手,在web服务的注入方面遇到了麻烦

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);

    }
}
这是ConfigureService方法:

    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>();

    }
   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());

    }
和配置服务方法:

    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>();

    }
   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());

    }
public void配置服务(IServiceCollection服务)
{            
services.AddMvc();
services.AddSingleton(配置);
services.AddDbContext(options=>options.UseSqlServer(Configuration.GetConnectionString(“SQLConnection”));
services.AddSoapExceptionTransformer((ex)=>ex.Message);
addScope(新的InstallService());
}
但是我需要使用webService将数据保存到SQL Server


我几乎可以肯定有什么不对的地方,但我想不出来。

你的问题似乎和我的不同

public class InstallService : IService
{
    private SQLContext _context;

    public InstallService(SQLContext context) 
    {
        _context = context;
    }  
}

你有这个例外

“System.ServiceModel.FaultException。非静态方法需要目标”

可能您没有得到
SQLContext
实例

请检查代码中的
Configuration.GetConnectionString(“SQLConnection”)

如果我错了,请纠正我p

要使用,请尝试将服务配置为

            services.AddScoped<IService, InstallService>();
services.addScope();
然后使用如下服务:

            app.UseSoapEndpoint<IService>("/ServicePath.asmx", new BasicHttpBinding());
app.UseSoapEndpoint(“/ServicePath.asmx”,新的BasicHttpBinding());

您正在使用ASP.NET Core托管WCF服务吗?为什么不在ASP.NET项目上创建一个WCF呢?您是否使用或实现自己的
UseSoapEndpoint
?services.addScope(new InstallService());这是你的问题,不要在这里新建。我已经运行了这个Web服务器,所以我正在尝试在其中附加Web服务。抱歉,我忘了告诉你我正在使用SoapCore谢谢你的回答,但是我已经在其他几个地方使用了SQLcontext,而且它工作得很好。我会尝试实现接口而不是类,我一尝试就给你回复。谢谢,谢谢!就这样,救了我一天。
            app.UseSoapEndpoint<IService>("/ServicePath.asmx", new BasicHttpBinding());