Skip to content

Commit c57415c

Browse files
committed
Refresh edits
1 parent 765f294 commit c57415c

File tree

8 files changed

+81
-49
lines changed

8 files changed

+81
-49
lines changed
113 KB
Loading
-747 Bytes
Loading

docs/data-tools/media/wcf2.png

24.1 KB
Loading

docs/data-tools/media/wcf3.png

24.1 KB
Loading

docs/data-tools/media/wcf4.png

341 Bytes
Loading

docs/data-tools/media/wcf5.png

259 Bytes
Loading

docs/data-tools/media/wcf6.png

232 Bytes
Loading

docs/data-tools/walkthrough-creating-a-simple-wcf-service-in-windows-forms.md

Lines changed: 81 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
---
2-
title: Create WCF Service in .NET Framework Windows Forms
2+
title: Create a WCF Service in .NET Framework Windows Forms
33
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
610
dev_langs:
711
- VB
812
- CSharp
@@ -11,144 +15,172 @@ helpviewer_keywords:
1115
- WCF, Visual Studio tools for
1216
- WCF services
1317
- 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+
1821
---
1922

20-
# Walkthrough: Create a simple WCF service in .NET Framework Windows Forms
23+
# Walkthrough: Create a WCF service in .NET Framework Windows Forms
2124

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.
2326

2427
[!INCLUDE[note_settings_general](../data-tools/includes/note_settings_general_md.md)]
2528

2629
## Prerequisites
2730

28-
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:
2932

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**.
3137

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
3341

34-
2. On the start window, choose **Create a new project**.
42+
1. In Visual Studio, select **File** > **New** > **Project** from the menu.
3543

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**.
3745

38-
![Create new WCF Service Library project in Visual Studio](media/vs-2019/create-new-wcf-service-library.png)
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":::
3947

4048
> [!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)
4250
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**.
4452

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.
4754

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.
4956

50-
![The IService1 file](../data-tools/media/wcf2.png)
57+
:::image type="content" alt-text="Screen shot that shows the IService1 file in Solution Explorer." source="../data-tools/media/wcf2.png":::
5158

52-
Find the following line:
59+
1. Find the following line:
5360

5461
### [C#](#tab/csharp)
62+
5563
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/iservice1_2.cs" id="Snippet4":::
5664

5765
### [VB](#tab/vb)
66+
5867
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/iservice1_2.vb" id="Snippet4":::
68+
5969
---
6070

61-
Change the type for the `value` parameter to string:
71+
1. Change the type for the `value` parameter to string, as follows:
6272

6373
### [C#](#tab/csharp)
74+
6475
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/iservice1.cs" id="Snippet1":::
6576

6677
### [VB](#tab/vb)
78+
6779
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/iservice1.vb" id="Snippet1":::
80+
6881
---
6982

70-
In the above code, note the `OperationContract` attribute. This attribute is required for any method exposed by the service.
83+
In the previous code example, note the `OperationContract` attribute. This attribute is required for any method exposed by the service.
7184

72-
6. In **Solution Explorer**, double-click **Service1.vb** or **Service1.cs**.
85+
1. In Solution Explorer, double-click **Service1.vb** or **Service1.cs**.
7386

74-
![The Service1 file](../data-tools/media/wcf3.png)
87+
:::image type="content" alt-text="Screen shot that shows the Service1 file in Solution Explorer." source="../data-tools/media/wcf3.png":::
7588

76-
Find the following line:
89+
1. In the editor, find the following line:
7790

7891
### [C#](#tab/csharp)
92+
7993
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/service1_2.cs" id="Snippet5":::
8094

8195
### [VB](#tab/vb)
96+
8297
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/service1_2.vb" id="Snippet5":::
98+
8399
---
84100

85-
Change the type for the `value` parameter to string:
101+
1. Change the type for the `value` parameter to string, as follows:
86102

87103
### [C#](#tab/csharp)
104+
88105
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/service1.cs" id="Snippet2":::
89106

90107
### [VB](#tab/vb)
108+
91109
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/service1.vb" id="Snippet2":::
110+
92111
---
93112

94113
## Test the service
95114

96-
1. Press **F5** to run the service. A **WCF Test Client** form appears and loads the service.
115+
1. Press **F5** to run the service.
97116

98-
2. In the **WCF Test Client** form, double-click the **GetData()** method under **IService1**. The **GetData** tab appears.
117+
The **WCF Test Client** form appears and loads the service.
99118

100-
![The GetData() method](../data-tools/media/wcf4.png)
119+
1. In the **WCF Test Client** form, under **IService1**, double-click the **GetData()** method.
101120

102-
3. In the **Request** box, select the **Value** field and type `Hello`.
121+
The **GetData** tab appears.
103122

104-
![The Value field](../data-tools/media/wcf5.png)
123+
:::image type="content" alt-text="Screenshot that shows the GetData method in the WCF Test Client form." source="../data-tools/media/wcf4.png":::
105124

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**.
107126

108-
![The result in the Response box](../data-tools/media/wcf6.png)
127+
:::image type="content" alt-text="Screenshot that shows the Value field in the GetData tab." source="../data-tools/media/wcf5.png":::
109128

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.
111136

112137
## Access the Service
113138

114139
### Reference the WCF service
115140

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.
117144

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**.
119146

120-
1. In the **Add Service Reference** dialog box, click **Discover**.
147+
The **Add Service Reference** dialog box appears.
121148

122-
![Screenshot showing the Add Service Reference dialog box.](../data-tools/media/vs-2022/add-service-reference-dialog-box.png)
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":::
123152

124153
**Service1** displays in the **Services** pane.
125154

126-
1. Click **OK** to add the service reference.
155+
1. Select **OK** to add the service reference.
127156

128157
### Build a client application
129158

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.
131160

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.
133162

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.
135164

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":::
137166

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:
139168

140169
### [C#](#tab/csharp)
170+
141171
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/form1.cs" id="Snippet3":::
142172

143173
### [VB](#tab/vb)
174+
144175
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/form1.vb" id="Snippet3":::
176+
145177
---
146178

147-
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**.
148180

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.
150182

151-
![Screenshot of the running form showing the result.](../data-tools/media/vs-2022/windows-forms-app.png)
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":::
152184

153185
## Related content
154186

0 commit comments

Comments
 (0)