You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data-tools/walkthrough-creating-a-simple-wcf-service-in-windows-forms.md
+96-52Lines changed: 96 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,12 @@
1
1
---
2
-
title: Create WCF Service in .NET Framework Windows Forms
2
+
title: Create a WCF Service in .NET Framework Windows Forms
3
3
description: Create a Windows Communication Foundation (WCF) service in Visual Studio, test the service, and access it from a Windows Forms application.
4
-
ms.date: 06/30/2023
5
-
ms.topic: conceptual
4
+
author: ghogen
5
+
ms.author: ghogen
6
+
manager: mijacobs
7
+
ms.subservice: data-tools
8
+
ms.topic: how-to
9
+
ms.date: 03/19/2025
6
10
dev_langs:
7
11
- VB
8
12
- CSharp
@@ -11,144 +15,184 @@ helpviewer_keywords:
11
15
- WCF, Visual Studio tools for
12
16
- WCF services
13
17
- WCF services, walkthrough
14
-
author: ghogen
15
-
ms.author: ghogen
16
-
manager: mijacobs
17
-
ms.subservice: data-tools
18
+
19
+
# Customer intent: As a developer, I want to understand how to create a WCF Service in .NET Framework so that I can access it from a Windows Forms app.
20
+
18
21
---
19
22
20
-
# Walkthrough: Create a simple WCF service in .NET Framework Windows Forms
23
+
# Walkthrough: Create a WCF service in .NET Framework Windows Forms
21
24
22
-
This walkthrough demonstrates how to create a simple Windows Communication Foundation (WCF) service, test it, and then access it from a .NET Framework Windows Forms application.
25
+
This walkthrough demonstrates how to create a Windows Communication Foundation (WCF) service, test it, and then access it from a .NET Framework Windows Forms application.
The WCF tools are not installed with the .NET workload; use the Visual Studio Installer to modify your installation. In the installer, choose **Windows Communication Foundation**under Individual Components. See [Modify Visual Studio](../install/modify-visual-studio.md).
31
+
[Visual Studio](https://visualstudio.microsoft.com/downloads/?cid=learn-onpage-download-cta) with the **Windows Communication Foundation**component installed. To install it:
29
32
30
-
## Create a service
33
+
1. Open the **Visual Studio Installer** app, or select **Tools** > **Get Tools and Features** from the Visual Studio menu.
34
+
1. In **Visual Studio Installer**, choose **Modify** next to the version of Visual Studio you want to modify.
35
+
1. Select the **Individual components** tab, and then choose **Windows Communication Foundation** under **Development activities**.
36
+
1. Select **Modify**.
31
37
32
-
1. Open Visual Studio.
38
+
For more information, see [Modify Visual Studio workloads, components, and language packs](../install/modify-visual-studio.md).
33
39
34
-
2. On the start window, choose **Create a new project**.
40
+
## Create a WCF service
35
41
36
-
3. Type **wcf service library**in the search box on the **Create a new project** page. Select either the C# or Visual Basic template for **WCF Service Library**, and then select **Next**.
42
+
To create a WCF service in Visual Studio, follow these steps:
37
43
38
-

44
+
1. In Visual Studio, select **File** > **New** > **Project** from the menu.
45
+
46
+
2. On the **Create a new project** page, enter **wcf service library** in the search box. Select either the C# or Visual Basic template for **WCF Service Library**, and then select **Next**.
47
+
48
+
:::image type="content" alt-text="Screenshot that shows how to create a WCF Service Library project in Visual Studio." source="../data-tools/media/vs-2022/create-new-wcf-service-library.png":::
39
49
40
50
> [!TIP]
41
-
> If you don't see any templates, you might need to install the **Windows Communication Foundation** component of Visual Studio. Choose **Install more tools and features** to open Visual Studio Installer. Choose the **Individual components** tab, scroll down to **Development activities**, and then select **Windows Communication Foundation**. Click **Modify**.
51
+
> If you don't see any templates, you might need to install the **Windows Communication Foundation** component of Visual Studio. For more information, see [Prerequisites](#prerequisites)
42
52
43
-
4. On the **Configure your new project** page, click**Create**.
53
+
3. On the **Configure your new project** page, verify the settings, and then select**Create**.
44
54
45
-
> [!NOTE]
46
-
> This creates a working service that can be tested and accessed. The following two steps demonstrate how you might modify the default method to use a different data type. In a real application, you would also add your own functions to the service.
55
+
This step creates a working WCF service that you can test and access. The following steps demonstrate how to modify the default method to use a different data type. In a real application, you'd also add your own functions to the service.
47
56
48
-
5. In **Solution Explorer**, double-click **IService1.vb** or **IService1.cs**.
57
+
4. In **Solution Explorer**, double-click **IService1.cs** or **IService1.vb** in your WCF service library project, depending on which type of project you created.
1. In the **Request** box of the **GetData** tab, select the **Value** field and enter **Hello**.
101
130
102
-
3. In the **Request** box, select the **Value** field and type `Hello`.
131
+
:::image type="content" alt-text="Screenshot that shows the Value field in the GetData tab." source="../data-tools/media/wcf5.png":::
103
132
104
-

133
+
1. Select the **Invoke** button. If a **Security Warning** dialog box appears, select **OK**.
105
134
106
-
4. Click the **Invoke** button. If a **Security Warning** dialog box appears, click **OK**. The result displays in the **Response** box.
135
+
The result displays in the **Response** box.
107
136
108
-

137
+
:::image type="content" alt-text="Screenshot that shows the result displayed in the Response box in the GetData tab." source="../data-tools/media/wcf6.png":::
109
138
110
-
5. On the **File** menu, click**Exit** to close the test form.
139
+
1. On the **File** menu, select**Exit** to close the test form.
111
140
112
-
## Access the Service
141
+
## Access the WCF service
142
+
143
+
After you create and test the WCF service, you can reference it from a project and use it to build a client application.
113
144
114
145
### Reference the WCF service
115
146
116
-
1. On the **File** menu, point to **Add > New Project**. Choose **Windows Forms App (.NET Framework)** project.
147
+
To reference the WCF service from a project, follow these steps:
148
+
149
+
1. Select **File** > **Add** > **New Project**.
150
+
151
+
1. In the **Add a New Project** window, choose either a C# or Visual Basic **Windows Forms App (.NET Framework)** project. Select **Next**, and then **Create** to create the project.
117
152
118
-
1.Right-click on the project node, and click**Add > Service Reference**. The**Add Service Reference** dialog box appears.
153
+
1.In **Solution Explorer**, right-click the project node of the new project, and select**Add** >**Service Reference**.
119
154
120
-
1. In the **Add Service Reference** dialog box, click **Discover**.
155
+
The **Add Service Reference** dialog box appears.
121
156
122
-

157
+
1. Select **Discover**.
158
+
159
+
:::image type="content" alt-text="Screenshot that shows the Add Service Reference dialog box." source="../data-tools/media/vs-2022/add-service-reference-dialog-box.png":::
123
160
124
161
**Service1** displays in the **Services** pane.
125
162
126
-
1.Click**OK** to add the service reference.
163
+
1.Select**OK** to add the service reference.
127
164
128
165
### Build a client application
129
166
130
-
1. In **Solution Explorer**, double-click **Form1.vb** or **Form1.cs** to open the Windows Forms Designer if it is not already open.
167
+
To use a WCF service reference to build a client application, follow these steps.
168
+
169
+
1. In **Solution Explorer**, double-click **Form1.cs** or **Form1.vb** in the Windows Forms app.
131
170
132
-
1. Open the **Toolbox** by clicking on **View** > **Toolbox** (or **Ctrl**+**Alt**+**X** on the keyboard).
171
+
The form opens in Windows Forms Designer.
133
172
134
-
1.From the **Toolbox**, drag a `TextBox` control, a `Label` control, and a `Button` control onto the form.
173
+
1.Open the **Toolbox** by selecting **View** > **Toolbox** from the menu, or press **Ctrl**+**Alt**+**X** from the keyboard.
135
174
136
-
:::image type="content" alt-text="Screenshot showing adding controls to the form." source="../data-tools/media/vs-2022/windows-communication-foundation-client-app.png" lightbox="../data-tools/media/vs-2022/windows-communication-foundation-client-app.png":::
175
+
1. From the **Toolbox**, drag a **TextBox** control, a **Label** control, and a **Button** control onto the form.
137
176
138
-
1. Double-click the `Button`, and add the following code in the `Click` event handler:
177
+
:::image type="content" alt-text="Screenshot that shows how to add controls to the client application form." source="../data-tools/media/vs-2022/windows-communication-foundation-client-app.png" lightbox="../data-tools/media/vs-2022/windows-communication-foundation-client-app.png":::
178
+
179
+
1. Double-click the **Button** control, and add the following code in the `Click` event handler:
1. In **Solution Explorer**, right-click the project node (for example, **WindowsFormsApp1**), and click**Set as StartUp Project**.
191
+
1. In **Solution Explorer**, right-click the project node (for example, **WindowsFormsApp1**), and select**Set as StartUp Project**.
148
192
149
-
1. Press **F5** to run the project. Enter some text and click the button. The label displays "You entered:" and shows the text that you entered.
193
+
1. Press **F5** to run the project. Enter some text and select the button. The label displays **You entered:**, followed by your text.
150
194
151
-

195
+
:::image type="content" alt-text="Screenshot that shows the result displayed in the running client application form." source="../data-tools/media/vs-2022/windows-forms-app.png":::
0 commit comments