Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consume wcf service in .net core which to use services.AddSingleton or services.AddTransient

I am consuming a WCF service in my .net core API project and I used the following steps:
The binding in WCF service (for testing) <add binding="basicHttpsBinding" scheme="https" />

  1. Created a proxy class using https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-svcutil-guide?tabs=dotnetsvcutil2x
    (This created a proxy which has an interface IService1 and calls Service1Client).

  2. In the startup class I have bound the interface with the class services.AddSingleton<IService1, Service1Client>();

The method endpoint in the WCF service gets the data form the database according to the parameter passed to consume the WCF service.

I am not sure which one I should use, services.AddSingleton or services.AddTransient, because I am not sure what the proxy class is using to call the method.

If I create a single instance, will it be locked?

I have done a Jmeter test with 1000 rows in the database and 1000 rows from csv as a parameter to consume the API, but did not find any lock and all were successful under 3 minutes.

like image 772
शेखर Avatar asked Sep 13 '25 10:09

शेखर


1 Answers

You can view the servicereference.cs file to see which method in the wcf service is called by the proxy class.

enter image description here

Then we need to instantiate the proxy class and call the WCF service through the instantiated proxy class:

ServiceReference.Service1Client service1 = new Service1Client();

enter image description here

like image 97
Ding Peng Avatar answered Sep 16 '25 06:09

Ding Peng