This article is a mirror article of machine translation, please click here to jump to the original article.

View: 63675|Reply: 8

[.NET Core] ASP.NET Core 3.1 Calling .NET 4.0 WCF Services tutorial

[Copy link]
Posted on 7/19/2020 10:18:08 PM | | | |
When developing a new project, using asp.net core technology, the old project may be a WCF service developed using the .NET Framework 4, because the reconstruction cost is too high, it is necessary to use asp.net core to call the WCF service interface.

First, create a new two projects:

ASP.NET Core 3.1 project: dotnet-core-call-wcf
.NET Framework 4 project (WCF service application): schools-wcf-service

Visual Studio 2019 wants to create a WCF service, can't find the template, solution:

Select Install more tools and features to open Visual Studio Installer. Select the Individual Components tab, scroll down to Development Activities, select Windows Communication Foundation, and click Modify.


WCF creates two interfaces as follows:

The interface implementation code is as follows:


A service contract is a collection of related service operations, and when we apply a ServiceContractAttribute on an interface, we give it a service contract attribute. However, for such a type, its idiom does not automatically become a contractual service operation, and only when the OperationContractAttribute feature is applied can the corresponding method member become a service operation that can be accessed by service call.

When you start the wcf project, it will automatically run WcfTestClient and try to call it as shown in the figure below:



Use ASP.NET Core projects to call WCF services

Right-click Connected Services, select the service you want to add a connection to, and select WCF service, as shown in the following image:



Service address filled: http://localhost:3705/Service1.svc

Possible errors:

WCF:Error:Unable to generate deps.json
https://www.itsvse.com/thread-9288-1-1.html

Since it is impossible to write the WCF service address to death, add the following code to the appsettings.json file:

Edit the Startup.cs file and register the WCF service with the following code:

Call the wcf service on the HomeController controller, first constructor injection, the code is as follows:

Calling the WCF service:

Run the asp.net Core website, the effect is as shown below:



We try to modify the WCF service so that the interface returns the result after 3 minutes, and then restart asp.net core to call the WCF service, and the error is as follows:

AggregateException: One or more errors occurred. (The request channel timed out attempting to send after 00:01:00. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.)

At this time, we need to modify the default timeout, customize the BasicHttpBinding binding, and re-edit the Startup.cs file, as follows:



Source code download:

Tourists, if you want to see the hidden content of this post, pleaseReply





Previous:Help with Windows registry corruption
Next:VS 2019 uses svcutil.exe tools to generate the call file
Posted on 9/15/2020 4:26:41 PM |
Learn it
Posted on 5/11/2021 1:58:38 PM |
There is a source code boss
Posted on 6/18/2021 3:07:44 PM |
Just to see
Posted on 6/18/2021 3:08:38 PM |
The code cannot be viewed
Posted on 6/28/2021 10:58:22 AM |
I haven't been able to get any results, what's going on?
Posted on 7/4/2021 10:21:09 AM |
Come back to learn from the gods, thank you for sharing
Posted on 8/3/2022 3:36:10 PM |
The same needs, come and learn
Posted on 12/2/2022 1:17:10 AM |
Learn from the gods
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com