BaluRaju-7713 avatar image
0 Votes"
BaluRaju-7713 asked Bruce-SqlWork commented

Web Config use

I have a typical requirement. We have several WCF services using NetHttpBinding. We are developing a new Core Web API for a new project.
We plan to use the existing WCF DLLs in new web API that. one of the DLLs is data layer that uses connection string form Web.config file.
The new Core Web API uses these existing DLLs. However, We cannot change the existing WCF services nor can we change the DLLs to use appsettings.json file because WCF Services are still used by legacy application.

First I thought I would just define the connection strings in web API appsettings.json. It did not work.
Next, I added a web config file to the new Core Web API and defined the connection strings there, it did not work.

I cannot call WCF service from Web API because it uses custom binding such as NetHTTPBinding that I may have define in Web API.

I could use WCF Dlls from any other application such as console application using the web config. I thought I could use same concept with Web API by referncing the DLLs directly, but the DLLs is reading neither the appsettings.json nor the web config file.

Any insight will be appreciated.

Here is the scenario
Current WCF Service S1 uses DLL D1. D1 uses web config to read the web config. this works as part of WCF services. No problem here.
Created a new Core Web API that uses its own appsettings.json. for its own connection string.
the new Core Web API uses the existing DLL D1. However, D1 does not read connection string from AppSeetings.json.
Then I added a Web Config file to the Core Web API. Still the DLL D1 does not read the connection string from Web.Config.

· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Why can't you leave the WCF services as is? Any new development implements Core.

Frankly, it is a little unusual that .NET framework DLLs will work in Core. If the code does work then extend the source by adding a constructor parameter that accepts the connection string. I can't see your code so I have no idea if this is possible or not.

0 Votes 0 ·

Yes, I'm not trying to change the WCF services because it is still used by the legacy app.
But I want to reuse the DLLs in WCF Services in new ASP net Core web api instead of rewriting things again. Basically I want to expose existing WCF services as DLLs wrapped in Core API to avoid writing things again.

So the legacy system will continue to use the WCF Services and the system system will use the Core API that contains WCF DLLs.

0 Votes 0 ·
AgaveJoe avatar image AgaveJoe BaluRaju-7713 ·

I assume that currently the DLLs have a hard dependency on the configuration manager. My suggestion is modifying the DLL source so you can pass the connection string from the Core app using basic constructor parameter. Or maybe a property. Of course you'll have a condition somewhere to determine where the connection string came from. I cannot see your code so have no idea if this is possible.

In my experience, it's unusual that a .NET framework DLL will work in .NET Core. Especially a project as old a WCF. The DLL must target a .NET Standard compatible with the .NET Core version you're targeting.

.NET Standard

Are you sure the DLLs work in Core?

0 Votes 0 ·
Show more comments

Hi @BaluRaju-7713,
WCF is built using the .NET Framework. The core Web API is .NET.

I could use WCF Dlls from any other application such as console application using the web config.

Does the console application's framework use the .NET Framework or .NET?
You can check what's new in .NET 5 / Windows Communication Foundation.

The original implementation of Windows Communication Foundation (WCF) was only supported on Windows. However, there is a client port available from the .NET Foundation. It is entirely open source, cross platform, and supported by Microsoft.

Best regards,
Lan Huang

0 Votes 0 ·
BaluRaju-7713 avatar image BaluRaju-7713 LanHuang-MSFT ·

WCF service and its supporting DLLs still use .Net Framework, did not want to change them. as they are still being used by the legacy system that is still targeted to .Net Framework.
What is the purpose of web config in web api when we have appsettings.json?
Although in the development there is no web.config file, but when I deploy, it created web config.

SO when a .Net framework based DLL can use web.config (If used in Service) or app.config (If used in WIndows Forms) associated with .Net Framework based applications such as Windows Forms or Console or in WCF Service application, why can't it use the web config associated with web api? I understand if it cannot read the appsettings.json.

Looks like my approach is not a good way.

0 Votes 0 ·
Bruce-SqlWork avatar image Bruce-SqlWork BaluRaju-7713 ·

as stated, for .net core to call the dll D1, it needs to be converted to .netstandard 2.0. to access configuration setting, the dll will need to use the new nuget package that supports configuration setting. this package will work with both platforms.

note: the web.config created on .net core deploy is for the IIS hosting module, it not used by core code.

0 Votes 0 ·

0 Answers