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
+81-49Lines changed: 81 additions & 49 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/16/2025
6
10
dev_langs:
7
11
- VB
8
12
- CSharp
@@ -11,144 +15,172 @@ 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 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 **Visual Studio Installer** or select **Tools** > **Get Tools and Features**.
34
+
1. In the 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).
39
+
40
+
## Create a service
33
41
34
-
2. On the start window, choose**Create a new project**.
42
+
1. In Visual Studio, select**File** > **New** > **Project** from the menu.
35
43
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**.
44
+
1. 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**.
37
45
38
-

46
+
:::image type="content" alt-text="Screen shot 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
47
40
48
> [!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**.
49
+
> 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
50
43
-
4. On the **Configure your new project** page, click**Create**.
51
+
1. On the **Configure your new project** page, verify the settings, and then select**Create**.
44
52
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.
53
+
This step creates a working WCF service that you can test and access. The following two 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
54
48
-
5. In **Solution Explorer**, double-click **IService1.vb** or **IService1.cs**.
55
+
1. 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 **WCF Test Client** form, under **IService1**, double-click the **GetData()** method.
101
120
102
-
3. In the **Request** box, select the **Value**field and type `Hello`.
121
+
The **GetData**tab appears.
103
122
104
-

123
+
:::image type="content" alt-text="Screenshot that shows the GetData method in the WCF Test Client form." source="../data-tools/media/wcf4.png":::
105
124
106
-
4. Click the **Invoke**button. If a **Security Warning** dialog box appears, click **OK**. The result displays in the **Response** box.
125
+
1. In the **Request** box, select the **Value** field and enter **Hello**.
107
126
108
-

127
+
:::image type="content" alt-text="Screenshot that shows the Value field in the GetData tab." source="../data-tools/media/wcf5.png":::
109
128
110
-
5. On the **File** menu, click **Exit** to close the test form.
129
+
1. Select the **Invoke** button. If a **Security Warning** dialog box appears, select **OK**.
130
+
131
+
The result displays in the **Response** box.
132
+
133
+
:::image type="content" alt-text="Screenshot that shows the result displayed in the Response box." source="../data-tools/media/wcf6.png":::
134
+
135
+
1. On the **File** menu, select **Exit** to close the test form.
111
136
112
137
## Access the Service
113
138
114
139
### Reference the WCF service
115
140
116
-
1. On the **File** menu, point to **Add > New Project**. Choose **Windows Forms App (.NET Framework)** project.
141
+
1. Select **File** > **Add** > **New Project**.
142
+
143
+
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
144
118
-
1.Right-click on the project node, and click**Add > Service Reference**. The**Add Service Reference** dialog box appears.
145
+
1.In Solution Explorer, right-click the project node of the new project, and select**Add** >**Service Reference**.
119
146
120
-
1. In the **Add Service Reference** dialog box, click **Discover**.
147
+
The **Add Service Reference** dialog box appears.
121
148
122
-

149
+
1. Select **Discover**.
150
+
151
+
:::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
152
124
153
**Service1** displays in the **Services** pane.
125
154
126
-
1.Click**OK** to add the service reference.
155
+
1.Select**OK** to add the service reference.
127
156
128
157
### Build a client application
129
158
130
-
1. In **Solution Explorer**, double-click **Form1.vb** or **Form1.cs** to open the Windows Forms Designer if it is not already open.
159
+
1. In Solution Explorer, depending on which type of project you created, double-click **Form1.cs**, or **Form1.vb**, in the Windows Forms app to open the Windows Forms Designer.
131
160
132
-
1. Open the **Toolbox** by clicking on **View** > **Toolbox**(or **Ctrl**+**Alt**+**X** on the keyboard).
161
+
1. Open the **Toolbox** by selecting **View** > **Toolbox**from the menu, or press **Ctrl**+**Alt**+**X** on the keyboard.
133
162
134
-
1. From the **Toolbox**, drag a `TextBox` control, a `Label` control, and a `Button` control onto the form.
163
+
1. From the **Toolbox**, drag a **TextBox** control, a **Label** control, and a **Button** control onto the form.
135
164
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":::
165
+
:::image type="content" alt-text="Screenshot that shows how to add 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":::
137
166
138
-
1. Double-click the `Button`, and add the following code in the `Click` event handler:
167
+
1. Double-click the **Button**, 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**.
179
+
1. In Solution Explorer, right-click the project node (for example, **WindowsFormsApp1**), and select**Set as StartUp Project**.
148
180
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.
181
+
1. Press **F5** to run the project. Enter some text and select the button. The label displays **You entered:** followed by the text that you entered.
150
182
151
-

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