0

I have a .NET 6 Winform application (C#) with an app.config and an appsettings section for which I am using AppSettingsReader to read the values.

I would like to add the equivalent of System.ServieModel, however, as soon as I do, the AppSettingsReader crashes with an unknown section.

Does anyone have an example of adding system.service model (WCF bindings) to a .NET 6 application (not a web app)?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
AndyW
  • 191
  • 1
  • 11
  • You have to use equivalent tools such as `System.ServiceModel.Primitives`. – Aria Apr 06 '22 at 04:42
  • .Net does not support WCF staff anymore, but you have options to consume WCF in .NET6, instead defining `system.serviceModel` in config you can define your `httpBinding`,`netTcpBinding` as `static` members programmatically. – Aria Apr 06 '22 at 05:23
  • NET does not currently support creating WCF services, but you can create WCF clients in .NET to call WCF services.If you want to use system.serviceModel, you need to install [System.ServiceModel.Http](https://www.nuget.org/packages/System.ServiceModel.Http). – Lan Huang Apr 06 '22 at 08:13
  • You can check [What's new in .NET 5](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-5#windows-communication-foundation) and [Add a WCF service reference](https://learn.microsoft.com/en-us/visualstudio/data-tools/how-to-add-update-or-remove-a-wcf-data-service-reference?view=vs-2022#to-add-a-reference-to-an-external-service-net-core-projects-including-net-5-and-later). – Lan Huang Apr 06 '22 at 08:14
  • Thanks for the replies. I created a .Net 4.8 application and implemented my code there by using the serviceModel in app.config and calling the client generated by svcutil. However, the same approach in .Net 6. results in an exception ConfigurationErrorsException: Unrecognised config section ServiceModel. I've tried to use the ServiceModel.Federation namespace to build the bindings in the app.config manually but have had no luck and don't seem to be able to find an example. – AndyW Apr 07 '22 at 03:09
  • Sorry forgot: I am creating the client endpoint, bindings and behaviors, not server side. – AndyW Apr 07 '22 at 03:10
  • Are you also using the `System.ServiceModel.Primitives` and `System.ServiceModel.Http` namespaces? You can refer to [this post](https://stackoverflow.com/a/28440491/17218587). – Lan Huang Apr 12 '22 at 02:53
  • Yes, anything with System.ServiceModel in it has been included. Same exception, Unrecognised section System.Service model. I would be interested in seeing if anyone has an example of using system.service model in app.config on a net.6 winform app. – AndyW Apr 13 '22 at 03:15
  • Maybe you can look at [this post](https://stackoverflow.com/questions/19589/loading-system-servicemodel-configuration-section-using-configurationmanager). – Lan Huang Apr 14 '22 at 08:02
  • Hi, thanks, I took a look through, however, the issue is that adding ServiceModel to the app.config causes the app to crash when it tries to read the app.config regardless of the approach taken to read the config file. I am still unable to find a .Net6 (console) application where someone is able to read that section. – AndyW May 04 '22 at 03:25

0 Answers0