November 1, 2020

.Net Core - Add WCF Reference

In this post, I will explain how you can add reference for a WCF Service in .Net Core Application, this will be a little bit different then how we consume WCF Service in regular .Net Framework.

In this example I have a WCF service already created, and I want to consume in .Net Core Console Application.

In Solution Explorer, right click on Connected Services node, and select Add Connected Service.

In Connected Services window, click on Microsoft WCF Web Service Reference Provider.

In the Service Endpoint tab, Enter the URL of WCF Service in the URL textbox and click Go button.

Type the desired namespace in Namespace textbox and click Next.

In the next tab Data Type Options, it will allow to change default options to generate client proxy. For example you can change Collection Type, the type from System.Array to System.Collections.Generic.List. Once you done with the changes click Next.

In Client Options tab, It will ask you to change the access level for generated classes. Default access level is public.

Click Finish button, and it will generate the required proxy classes to call WCF.

When the process completed, you are done with adding WCF reference.

Once you are done with adding reference, you can create an instance of the generated WCF client type and invoke the service operations as follows:

	BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
	EndpointAddress endpointAddress = 
          		new EndpointAddress("http://localhost:8081/OrderManagement/OrderManagement.svc");
	OrderManagementClient wcfClient =
    			new OrderManagementClient(basicHttpBinding, endpointAddress);
	var result = wcfClient.GetOrderByID(1);

References:

Related Post(s):

No comments:

Post a Comment