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
+38-28Lines changed: 38 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ ms.author: ghogen
6
6
manager: mijacobs
7
7
ms.subservice: data-tools
8
8
ms.topic: how-to
9
-
ms.date: 03/16/2025
9
+
ms.date: 03/17/2025
10
10
dev_langs:
11
11
- VB
12
12
- CSharp
@@ -30,33 +30,35 @@ This walkthrough demonstrates how to create a Windows Communication Foundation (
30
30
31
31
[Visual Studio](https://visualstudio.microsoft.com/downloads/?cid=learn-onpage-download-cta) with the **Windows Communication Foundation** component installed. To install it:
32
32
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.
33
+
1. Open **Visual Studio Installer** or select **Tools** > **Get Tools and Features** from the menu.
34
+
1. In **Visual Studio Installer**, choose **Modify** next to the version of Visual Studio you want to modify.
35
35
1. Select the **Individual components** tab, and then choose **Windows Communication Foundation** under **Development activities**.
36
36
1. Select **Modify**.
37
37
38
38
For more information, see [Modify Visual Studio workloads, components, and language packs](../install/modify-visual-studio.md).
39
39
40
-
## Create a service
40
+
## Create a WCF service
41
+
42
+
To create a WCF service in Visual Studio, follow these steps:
41
43
42
44
1. In Visual Studio, select **File** > **New** > **Project** from the menu.
43
45
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**.
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**.
45
47
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":::
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":::
47
49
48
50
> [!TIP]
49
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)
50
52
51
-
1. On the **Configure your new project** page, verify the settings, and then select **Create**.
53
+
3. On the **Configure your new project** page, verify the settings, and then select **Create**.
52
54
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.
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.
54
56
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.
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.
56
58
57
-
:::image type="content" alt-text="Screen shot that shows the IService1 file in Solution Explorer." source="../data-tools/media/wcf2.png":::
59
+
:::image type="content" alt-text="Screenshot that shows the IService1 file in Solution Explorer." source="../data-tools/media/wcf2.png":::
58
60
59
-
1. Find the following line:
61
+
5. Find the following line:
60
62
61
63
### [C#](#tab/csharp)
62
64
@@ -68,7 +70,7 @@ For more information, see [Modify Visual Studio workloads, components, and langu
68
70
69
71
---
70
72
71
-
1. Change the type for the `value` parameter to string, as follows:
73
+
6. Change the type for the `value` parameter to string, as follows:
72
74
73
75
### [C#](#tab/csharp)
74
76
@@ -78,15 +80,15 @@ For more information, see [Modify Visual Studio workloads, components, and langu
In this code example, note the `OperationContract` attribute. This attribute is required for any method exposed by the service.
82
84
83
-
In the previous code example, note the `OperationContract` attribute. This attribute is required for any method exposed by the service.
85
+
---
84
86
85
-
1. In Solution Explorer, double-click **Service1.vb** or **Service1.cs**.
87
+
7. In Solution Explorer, double-click **Service1.cs** or **Service1.vb**.
86
88
87
-
:::image type="content" alt-text="Screen shot that shows the Service1 file in Solution Explorer." source="../data-tools/media/wcf3.png":::
89
+
:::image type="content" alt-text="Screenshot that shows the Service1 file in Solution Explorer." source="../data-tools/media/wcf3.png":::
88
90
89
-
1. In the editor, find the following line:
91
+
8. In the editor, find the following line:
90
92
91
93
### [C#](#tab/csharp)
92
94
@@ -98,7 +100,7 @@ For more information, see [Modify Visual Studio workloads, components, and langu
98
100
99
101
---
100
102
101
-
1. Change the type for the `value` parameter to string, as follows:
103
+
9. Change the type for the `value` parameter to string, as follows:
102
104
103
105
### [C#](#tab/csharp)
104
106
@@ -110,34 +112,40 @@ For more information, see [Modify Visual Studio workloads, components, and langu
110
112
111
113
---
112
114
113
-
## Test the service
115
+
## Test the WCF service
116
+
117
+
To test the WCF service you created, follow these steps:
114
118
115
119
1. Press **F5** to run the service.
116
120
117
121
The **WCF Test Client** form appears and loads the service.
118
122
119
-
1.In the **WCF Test Client** form, under**IService1**, double-click the **GetData()** method.
123
+
1.Under**IService1**, double-click the **GetData()** method.
120
124
121
-
The **GetData** tab appears.
125
+
The **GetData** tab appears in the **WCF Test Client** form.
122
126
123
127
:::image type="content" alt-text="Screenshot that shows the GetData method in the WCF Test Client form." source="../data-tools/media/wcf4.png":::
124
128
125
-
1. In the **Request** box, select the **Value** field and enter **Hello**.
129
+
1. In the **Request** box of the **GetData** tab, select the **Value** field and enter **Hello**.
126
130
127
131
:::image type="content" alt-text="Screenshot that shows the Value field in the GetData tab." source="../data-tools/media/wcf5.png":::
128
132
129
133
1. Select the **Invoke** button. If a **Security Warning** dialog box appears, select **OK**.
130
134
131
135
The result displays in the **Response** box.
132
136
133
-
:::image type="content" alt-text="Screenshot that shows the result displayed in the Response box." source="../data-tools/media/wcf6.png":::
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":::
134
138
135
139
1. On the **File** menu, select **Exit** to close the test form.
136
140
137
-
## Access the Service
141
+
## Access the WCF service
142
+
143
+
Now that you created and tested the WCF service, you can reference it from a project and use it to build a client application.
138
144
139
145
### Reference the WCF service
140
146
147
+
To reference the WCF service from a project, follow these steps:
148
+
141
149
1. Select **File** > **Add** > **New Project**.
142
150
143
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.
@@ -156,15 +164,17 @@ For more information, see [Modify Visual Studio workloads, components, and langu
156
164
157
165
### Build a client application
158
166
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.
167
+
1. In Solution Explorer, depending on which type of project you created, double-click **Form1.cs**, or **Form1.vb**, in the Windows Forms app.
168
+
169
+
The form opens in Windows Forms Designer.
160
170
161
171
1. Open the **Toolbox** by selecting **View** > **Toolbox** from the menu, or press **Ctrl**+**Alt**+**X** on the keyboard.
162
172
163
173
1. From the **Toolbox**, drag a **TextBox** control, a **Label** control, and a **Button** control onto the form.
164
174
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":::
175
+
:::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":::
166
176
167
-
1. Double-click the **Button**, and add the following code in the `Click` event handler:
177
+
1. Double-click the **Button** control, and add the following code in the `Click` event handler:
168
178
169
179
### [C#](#tab/csharp)
170
180
@@ -180,7 +190,7 @@ For more information, see [Modify Visual Studio workloads, components, and langu
180
190
181
191
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.
182
192
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":::
193
+
:::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