I added the reference to the project and I added this to IServiceCollection
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)
private Task<GetVariableOfProductResponse> GetVariableOfProductAsync(GetVariableRequest input, CancellationToken none)
private Task<CalculateResponse> CalculateAsync(Request input, CancellationToken none)
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?
To clarify, you don't have any knowledge of the service in your app? You're literally building a dynamic service calling app? The user types in a URL, you retrieve the WSDL and build a UI up to dynamically call the service? Sort of like the WCF Test Client. Jf the WSDL is the same but the URL changes then that is exactly how connected services are supposed to work.
For a truly dynamic proxy then you have to manually generate the bindings and all that which is potentially painful given the possible combinations involved. Also be aware services can support multiple bindings so you have to decide which one to use.
Looking at your code it looks like you're trying to use HTTP to make the SOAP call. This probably isn't going to work as you need to use the WCF client classes instead, specifically ClientBase. Otherwise you're going to end up having to implement a lot of SOAP boilerplate logic. As part of using that type you'll need a Binding and Endpoint which is where the URL and binding information comes in that you are asking about. Given that it is a generic I have found that it is generally easier to dynamically generate the type info via
svcutiland then load that generated assembly at runtime. Perf isn't great.
I'll also point out that SoapHttpClientProtocl is really useful as well but it isn't supported in .NET Core+. But you could potentially look at that code for some ideas.