I am migrating a console app (REST client app) from .NET framework to .NET Core.
In my current (framework) version, I use the app.config file to set the System.Net configuration:
<system.net>
<connectionManagement>
<add address="*" maxconnection="65535"/>
</connectionManagement>
</system.net>
In .NET Core, I have to use a JSON file for configuration. There is no documentation for implementing these settings using the new configuration schema. Does anyone know how this might look inside the new JSON config, or the correct way to implement this in Core? Do I need to build a designated "System.Net.json" config file (separate from an AppSettings.json) specifically to do this?
Thanks.
I assume you're trying to avoid the limit of 2 connections per endpoint, which is default on .NET Framework. Such limit does not exist on .NET Core. So you don't need the above setting at all.
Note that to achieve better perf, we recommend to use HttpClient/HttpClientHandler over HttpWebRequest/ServicePoint on .NET Core. HttpWebRequest/ServicePoint APIs are compat-only.
If you want to limit HttpClient connections, then use HttpClientHandler.MaxConnectionsPerServer
Assuming you are using Kestrel as your web server (and not doing it through IIS implementation), you should be able to set this in your UseKestrel in your BuildWebHost.
It would go something like this:
.UseKestrel(options =>
{
options.Limits.MaxConcurrentConnections = 100;
})
You can also add this in your HttpClientHandler, It's called MaxConnectionsPerServer. It can be seen here.
Some addition to Karel Zikmund answer. (As i don’t have permissions to comment).
According to this doc connections are limited since .net core 2.0:
https://learn.microsoft.com/en-us/dotnet/api/system.net.servicepointmanager.defaultconnectionlimit?view=netcore-3.1
What is missed in doc is if ServicePointManager used for .net core HttpClient implementation. According to this info it is used in .net core, but for HttpWebRequest, not HttpClient: https://github.com/dotnet/runtime/issues/26048
Related
Im trying to get a definition of our AppSettings and ConnectionStrings.
I would like to be able to "fetch" the following:
Key (Name of setting)
Value (The value of the setting)
Provider/builder (From which provider the setting were "picked from", since we use configuraiton builders, such as the UserSecrets and Environment config builders).
The problem is that the application that "requires" this is using ASP.net 4.8.
If this would have been ASP.net core 3+, I could simply use IConfigurationRoot.GetDebugView, or well.. I could simply have a look at the source code of that method and recreate what I need.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.configurationrootextensions.getdebugview?view=dotnet-plat-ext-6.0
https://andrewlock.net/debugging-configuration-values-in-aspnetcore/
But I cant find anything simulair in .Net Framework.
I have tried to find a way to eaither get all Config Builders and then use the keys from ConfigurationManager.AppSettings.AllKeys and ConfigurationManager.ConnectionStrings.AllKeys
and then for each ConfigBuilder call their GetValue-methods which takes a key.. this could work, but Im still unable to get all my configured Configuration Builders. Any ideas?
I'm building a suite of REST micro-services using .Net Core 3.0 Preview 6. All these services will have the same start up logic. So, I'm trying to place all the code in a .Net Standard library.
The goal is to have the IHostBuilder:CreateHostBuilder method, as well as the Startup:Configure and Startup:ConfigureServices class and methods in the library. The library will also contain error handling logic, customized http response messages, etc.
However, I can't seem to find the correct package that contains the ConfigureWebHostDefaults method. I tried adding the Microsoft.AspNetCore package 2.2.0, but that didn't resolve the issue.
I added the Microsoft.Extensions.Hosting (3.0.0-preview-6) package, that also doesn't resolve the issue.
Is what I'm attempting even possible?
Thanks
-marc
I resolved it, not the best way, but it works. I decided to make the library targeted specifically for .NET Core 3.0. So, I changed the targetframework in the project file. That change automatically resolved my other issue.
Import the Microsoft.AspNetCore package, and use WebHost.CreateDefaultBuilder() instead. According to the code it is built from, both CreateDefaultBuilder() and ConfigureWebHostDefaults() call the same internal method: ConfigureWebDefaults().
The only downside of this is that the returned host will be an IWebHost instead of an IHost.
I am using a JSON parser to extract the value and I am using the following jar
json-path-2.1.0, and I am getting the following error when I invoke the use case deployed as webservice on weblogic server
I wrote a small main program to extract the value from the json string and it works fine, but the server version of the use case is giving the issue. I am not sure if there are any other jars part of my ear can negatively impact this
SEVERE: defaultReader
java.lang.NoSuchFieldError: defaultReader
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39)
at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:174)
at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
Stumbled about the same problem.
The reason why it does not work is not the JDK 8.
The reason why you encounter this issue, is the fact that weblogic 12.2.1.X is bundling some old version of json-smart.
On my machine this would be found here:
jar:file:/C:/dev/WLS_12_2_1_2_0/oracle_common/modules/net.minidev.json-smart.jar!/net/minidev/json/JSONValue.class
Now if you are using a library like json-path that depends on json-smart, then by default the container will load the required class using one of its built-in modules.
The blowup you have, seems to be that the JSONValue class that your json-path depends on seemed to have this defaultReder field.
Here is a snipet of the clode that is blowing up.
public JsonSmartJsonProvider() {
this(JSONParser.MODE_PERMISSIVE, JSONValue.defaultReader.DEFAULT_ORDERED);
}
That
JSONValue.defaultReader
Seems not to be valid on weblogs older system class loader class.
You can tell the container to use what you are packing by putting into your weblogic.xml deployment descriptor something like this:
<wls:prefer-application-packages>
<wls:package-name>net.minidev.json.*</wls:package-name>
</wls:prefer-application-packages>
I am having quite a bit of trouble getting weblogic to swallow the fine-grained instruction above.
I found myself to force weblogic to swallog all that goes into the web-inf folder instead doing:
<wls:container-descriptor>
<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>
I would have rather not be using a hammer like the web-inf-classes, but I am dancing with the weblogic system classloader when I do not go coarse grained...
Regards.
I too was facing this issue, It turned out some other library was using json-smart's older version, and it was getting precedence over json-path's json-smart dependency. Removing the other jar solved the issue. Or you can also downgrade your json-path's version to appropriate version such that it support json-smart's older version.
Looks like JsonParser jar is present in JVM 1.8 version and it seems to have more precedence over the JsonParser class available in Json-path.jar. Apparently the us case doesn't work in 12.2.1 version of the weblogic server but it works fine in 12.1.3
I had the same problem but I use Gradle so I had to add:
compile group: 'net.minidev', name: 'json-smart', version: '2.3' to my dependencies.
According to the ASP .NET 5, you can supposedly write a custom config provider by inheriting from ConfigurationSource.
However, as with many other things, the API seems to have changed and this doesn't seem to work with the RC.
What is the current way to do this?
Your provider has to implement IConfigurationProvider. It can also inherit from ConfigurationProvider which implements the required interface.
Take a look at the implementation of the current providers:
CommandLineConfigurationProvider
EnvironmentVariablesConfigurationProvider
JsonConfigurationProvider
I have a Asp.net C# MVC 3 application implementing the Sharp Architecture. I have been trying to get Quartz.net to setup and work nicely with Castle Windsor for a few days without any luck. Based on what I know, I have setup everything correctly, but continue to have issues.
In my Global.cs file, creating my Container and trying to register quartz jobs:
var container = new WindsorContainer(new XmlInterpreter("quartz_jobs.xml"));
container.AddFacility("quartznet", new QuartzFacility());
In my quartz_jobs.xml file I have the following contents:
<?xml version="1.0" encoding="utf-8" ?>
<quartz xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
overwrite-existing-jobs="true">
<job>
<job-detail>
<name>DeleteLoansWithoutClientsJob</name>
<job-type>EasyOptions.Web.Mvc.Code.Jobs.DeleteLoansWithoutClientsJob, EasyOptions.Web.Mvc</job-type>
<durable>true</durable>
</job-detail>
<trigger>
<cron>
<name>DeleteLoansWithoutClientsJobTrigger</name>
<group>MyJobs</group>
<description>A description</description>
<job-name>DeleteLoansWithoutClientsJob</job-name>
<job-group>MyJobs</job-group>
<cron-expression>0 0/1 * * * ?</cron-expression>
</cron>
</trigger>
</job>
Problem is, you're pointing Windsor to the Quartz.NET config file.
There are two separate configurations: Windsor's and Quartz.NET's. Windsor is usually configured with code nowadays (i.e. fluent config), though it still supports XML configuration. However the Quartz.NET facility doesn't currently support code config, you have to use Windsor's XML config (at least for this, other components/facilities may still be configured via code). Then there's Quartz.NET, usually configured via an external quartz_jobs.xml file.
I recommend using the Quartz.NET facility sample app as reference. In particular, here's the sample Windsor config and the sample Quartz.NET config.
EDIT: if Quartz.NET says it can't find quartz_jobs.xml in a web application you need to include the web root in the configuration path: "~/quartz_jobs.xml" (instead of plain "quartz_jobs.xml")
I've written a blog post on how to integrate Quartz.NET with an IoC container. My example code uses Castle Windsor.
The blog post can be found here: http://thecodesaysitall.blogspot.com/2012/02/integrate-quartznet-with-your-favourite.html