I added the reference to the project and I added this to IServiceCollection
services.AddScoped<IServiceClient,ServiceClient>(x =>
new ServiceClient($"{configuration.GetValue<string>(Constant.Url)}")
);
Class ServiceClient
public class ServiceClient : IServiceClient
{
private string urlService;
private WCFServiceReference.WCFServiceServiceClient _WCFServiceServiceClient; //WCF Service to wrap
public ServiceClient(string urlService)
{
this.urlService = urlService;
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
this._WCFServiceServiceClient = new WCFServiceReference.WCFServiceServiceClient(basicHttpBinding, new EndpointAddress(this.urlService));
}
public Task<CalculateResponse> CalculateAsync(Request input)
{
return CalculateAsync(input, CancellationToken.None);
}
public Task<GetProductListResponse> GetProductListAsync(ProductRequest input)
{
return GetElencoProdottiAsync(input, CancellationToken.None);
}
public Task<GetVariableOfProductResponse> GetVariableOfProductAsync(GetVariableRequest input)
{
return GetVariableOfProductAsync(input, CancellationToken.None);
}
private Task<GetProductListResponse> GetProductListAsync(ProductRequest input, CancellationToken none)
{
return this._WCFServiceServiceClient.GetProductListAsync(input);
}
private Task<GetVariableOfProductResponse> GetVariableOfProductAsync(GetVariableRequest input, CancellationToken none)
{
return this._WCFServiceServiceClient.GetVariableOfProductAsync(input);
}
private Task<CalculateResponse> CalculateAsync(Request input, CancellationToken none)
{
return this._WCFServiceServiceClient.CalculateAsync(input);
}
}
When I start my application, this call CreateHostBuilder(args).Build().Run();
in Main rises the following Excpetion:
Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Namespace.IProductService Lifetime: Scoped ImplementationType: Namespace.ProductService': Unable to resolve service for type 'Namespace.ServiceClient' while attempting to activate 'Namespace.ProductService'.)
Would it be convenient for me to do the direct add to the wcf service?