I have a problem while adding WCF in the .NET core project.
When I used .net in the past I can add multiple environments in web.config
so I can load the correct web service at runtime (Dev, Rec, Prod).
The problem in the .net core project when I added a reference of my WCF service as Connected Service it created one file ConnectedService.json that contains a URL for the WCF service.
{
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
"Version": "15.0.20406.879",
"GettingStartedDocument": {
"Uri": "https://go.microsoft.com/fwlink/?linkid=858517"
},
"ExtendedData": {
"Uri": "*****?singleWsdl",
"Namespace": "Transverse.TokenService",
"SelectedAccessLevelForGeneratedClass": "Public",
"GenerateMessageContract": false,
"ReuseTypesinReferencedAssemblies": true,
"ReuseTypesinAllReferencedAssemblies": true,
"CollectionTypeReference": {
"Item1": "System.Collections.Generic.List`1",
"Item2": "System.Collections.dll"
},
"DictionaryCollectionTypeReference": {
"Item1": "System.Collections.Generic.Dictionary`2",
"Item2": "System.Collections.dll"
},
"CheckedReferencedAssemblies": [],
"InstanceId": null,
"Name": "Transverse.TokenService",
"Metadata": {}
}
}
My question how can I load the correct service based on the used environment.
Note.
In my Project, I did not have an appsettings
neither web config. It is a .net core class library and it is called in ASP.NET core Application as Middleware.
To use WCF services in . NET Core, you need to create a proxy client of the required service. Proxy is actually a contract equivalent of actual service and contains complete details of the Interface and method exposed by WCF service. One can also use the Channel factory technique to connect to the WCF service easily.
NET Standard project, this option is available when you right-click on the Dependencies node of the project in Solution Explorer and choose Manage Connected Services.) On the Connected Services page, select Add Service Reference. The Add service reference page opens. Select WCF Web Service, and then choose Next.
In the Project Type pane, select a Visual C# application. In the Templates pane, select a Windows Forms Application. Enter a project name such as CallingServiceExample, and browse to a storage location. In the Solution Explorer, right-click the project name and click Add Service Reference.
As I understand from this article, this is Microsoft's recommendation:
ConfigureEndpoint()
Method by Setting a new value for Endpoint Example:
namespace Your_Reference_Service_Namespace
{
public partial class Your_Reference_Service_Client
{
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials)
{
serviceEndpoint.Address =
new System.ServiceModel.EndpointAddress(new System.Uri("http://your_web_service_address"),
new System.ServiceModel.DnsEndpointIdentity(""));
}
}
}
Here, you can take the value from the appsettings.json
file
new System.Uri(configuration.GetValue("yourServiceAddress")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With