Posts Tagged WCF
In this article we will discuss on the procedures to host a WCF Service on WebApps in Azure App Service. Azure App Serivce consists of four sub types and they are
- Web Apps – Provides hosting service for Web Applications
- Mobile Apps – Provides a mobile-application development platform that’s highly scalable.
- Logic Apps – Provides a visual designer to automate the business process in a series of workflow
- API Apps – Provides design and hosting services for Rest API
Usually we use Cloud Services on Azure to host WCF services. While Cloud Services hosting works as expected, the requirement we got was to find an option to host wcf service using one of the features in Azure AppService itself.
We can use WebApps feature to host the WCF in Azure AppService. Follow along this article to find out the procedures.
Step 1: Right Click on WCF Project in Visual Studio and Select the Publish Option
Step 2: Publish dialog box will display. In that Select the Microsoft Azure AppService option. If you are deploying WCF Service for the first time then select “Create New” and click on Publish Button
Step 3: Now we will see the App Service configuration dialog window. In the dialog window, we have to create the configuration details for WebApp in Azure
- App Name – Name of the hosted wcf service application in azure
- Subscription – Your active subscription for Azure. This field will be auto populated when you login to azure
- Resource Group – Enables you to work with the resources in your solution as a
- App Service Plan – Option to select the deployment location and the App Service Plan for deployment
Step 4: Before publishing to Azure, Make sure the application type is “Web App”
Step 5: Click on Create button to start deployment to Azure. You can also find the status of deployment in Output Window of Visual Studio
Step 6: After successful deployment, the published WCF Service will be displayed on the App Service section on Azure portal.Step 7: Click on Published WCF Service to find more details and URL of service.
Accessing the WCF Service
Create a console app as client application for WCF Service. Right click on console app and use the Add -> Service Reference option to access wcf service on client application
Once we add the WCF Service reference, we can call the WCF method like below
How to access WCF Service in Asp.Net Core Application
In this article I will explain how to consume WCF Service in Asp.Net Core Web Application. In previous .Net Framework we have multiple options to consume a WCF service. We have the options like Add Service Reference, SvcUtil, ChannelFactory etc. However in Asp.Net Core there is a slight difference in Consuming WCF Service. In Asp.Net core you will notice that, we don’t have the option “Add Service Reference like in the older .Net Framework. The solution for this is WCFConectedService.
Asp.net Core team has come up with an extension called WCFConnectedService, This is a Visual Studio extension for generating SOAP service references in the Asp.Net Core application. This extension can be used with any project types in asp.net core.
We use ConnectedService to access a WCF Service in Asp.Net Core Web Application.
Installing WCF Connected Service Extension:
Below are the steps to install WCF Connected Service Extension in Asp.Net Core WebApplication
- Right Click on the Connected Services Option
If the Extension is not installed then you will see the below window. User need to click on Find more Services link
Extension and Updates window will be displayed and from this window you can find the Visual Studio WCF Connected Service extension option
Click on Download button to install the extension. You may need to close the VisualStudio instances to complete the VSIX installation.
Simple WCF Service
For this example, we have created a WCF Service. In our service we have a sample method called “GetData(int id)”. This method will take integer input values and return a string “You entered:1”
SimpleService Method Implementation
Above service is for demo purpose, you can use connected service approach with any service as per your design.
Accessing WCF Service in Asp.Net Core Web Application
In your Asp.Net Core web application, you will see a Connected Service Option like below
Follow the below steps to Add Service Reference
- Right Click on the Connected Services Option
- Select Add Connected Service and Add Connected Services wizard will be displayed and Select the WCF -Service Preview option
- Click on the Configure button. This will bring up Configure WCF Service Reference dialog box. Enter your Service url and Click on Go or Discover, it will discover the Service
- Click on Next and select appropriate options
- Click on Finish to generate proxy for WCF Service.
Once after this you will be able to see Service Reference Folder added in our project.
Now all you need to is to Create the Client and access the service like below
You can download sample application for this article from here