Skip to content

Commit a4cb871

Browse files
committed
sync
2 parents b7e4fab + c5c4fa8 commit a4cb871

35 files changed

+286
-161
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: 96 additions & 52 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/19/2025
610
dev_langs:
711
- VB
812
- CSharp
@@ -11,144 +15,184 @@ 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 that 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 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**.
3137

32-
1. Open Visual Studio.
38+
For more information, see [Modify Visual Studio workloads, components, and language packs](../install/modify-visual-studio.md).
3339

34-
2. On the start window, choose **Create a new project**.
40+
## Create a WCF service
3541

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

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

4050
> [!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)
4252
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**.
4454

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

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

50-
![The IService1 file](../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":::
5160

52-
Find the following line:
61+
5. Find the following line:
5362

5463
### [C#](#tab/csharp)
64+
5565
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/iservice1_2.cs" id="Snippet4":::
5666

5767
### [VB](#tab/vb)
68+
5869
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/iservice1_2.vb" id="Snippet4":::
70+
5971
---
6072

61-
Change the type for the `value` parameter to string:
73+
6. Change the type for the `value` parameter to string.
74+
75+
In this code example, note the `OperationContract` attribute. This attribute is required for any method exposed by the service.
6276

6377
### [C#](#tab/csharp)
78+
6479
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/iservice1.cs" id="Snippet1":::
6580

6681
### [VB](#tab/vb)
82+
6783
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/iservice1.vb" id="Snippet1":::
68-
---
6984

70-
In the above code, note the `OperationContract` attribute. This attribute is required for any method exposed by the service.
85+
---
7186

72-
6. In **Solution Explorer**, double-click **Service1.vb** or **Service1.cs**.
87+
7. In **Solution Explorer**, double-click **Service1.cs** or **Service1.vb**.
7388

74-
![The Service1 file](../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":::
7590

76-
Find the following line:
91+
8. In the editor, find the following line:
7792

7893
### [C#](#tab/csharp)
94+
7995
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/service1_2.cs" id="Snippet5":::
8096

8197
### [VB](#tab/vb)
98+
8299
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/service1_2.vb" id="Snippet5":::
100+
83101
---
84102

85-
Change the type for the `value` parameter to string:
103+
9. Change the type for the `value` parameter to string, as follows:
86104

87105
### [C#](#tab/csharp)
106+
88107
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/service1.cs" id="Snippet2":::
89108

90109
### [VB](#tab/vb)
110+
91111
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/service1.vb" id="Snippet2":::
112+
92113
---
93114

94-
## Test the service
115+
## Test the WCF service
116+
117+
To test the WCF service you created, follow these steps:
118+
119+
1. Press **F5** to run the service.
120+
121+
The **WCF Test Client** form appears and loads the service.
122+
123+
1. Under **IService1**, double-click the **GetData()** method.
95124

96-
1. Press **F5** to run the service. A **WCF Test Client** form appears and loads the service.
125+
The **GetData** tab appears in the **WCF Test Client** form.
97126

98-
2. In the **WCF Test Client** form, double-click the **GetData()** method under **IService1**. The **GetData** tab appears.
127+
:::image type="content" alt-text="Screenshot that shows the GetData method in the WCF Test Client form." source="../data-tools/media/wcf4.png":::
99128

100-
![The GetData() method](../data-tools/media/wcf4.png)
129+
1. In the **Request** box of the **GetData** tab, select the **Value** field and enter **Hello**.
101130

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

104-
![The Value field](../data-tools/media/wcf5.png)
133+
1. Select the **Invoke** button. If a **Security Warning** dialog box appears, select **OK**.
105134

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

108-
![The result in the Response box](../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":::
109138

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

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

114145
### Reference the WCF service
115146

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

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

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

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

124161
**Service1** displays in the **Services** pane.
125162

126-
1. Click **OK** to add the service reference.
163+
1. Select **OK** to add the service reference.
127164

128165
### Build a client application
129166

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

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

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

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

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

140181
### [C#](#tab/csharp)
182+
141183
:::code language="csharp" source="../snippets/csharp/VS_Snippets_VBCSharp/wcfwalkthrough/cs/form1.cs" id="Snippet3":::
142184

143185
### [VB](#tab/vb)
186+
144187
:::code language="vb" source="../snippets/visualbasic/VS_Snippets_VBCSharp/wcfwalkthrough/vb/form1.vb" id="Snippet3":::
188+
145189
---
146190

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

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

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

153197
## Related content
154198

docs/extensibility/how-to-diagnose-ui-delays-caused-by-extensions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ You can also further filter this view by only including stacks that contain modu
146146
PerfView has detailed guidance under the **Help** menu that you can use to identify performance bottlenecks in your code. Additionally, the following links provide more information on how to utilize Visual Studio threading APIs to optimize your code:
147147

148148
* [`https://github.com/Microsoft/vs-threading/blob/main/doc/index.md`](https://github.com/Microsoft/vs-threading/blob/main/doc/index.md)
149-
* [`https://github.com/Microsoft/vs-threading/blob/main/doc/cookbook_vs.md`](https://github.com/Microsoft/vs-threading/blob/main/doc/cookbook_vs.md)
149+
* [`https://github.com/microsoft/vs-threading/blob/main/docfx/docs/cookbook_vs.md`](https://github.com/microsoft/vs-threading/blob/main/docfx/docs/cookbook_vs.md)
150150

151-
You can also use the new Visual Studio static analyzers for extensions (NuGet package [here](https://www.nuget.org/packages/microsoft.visualstudio.sdk.analyzers)), that provide guidance on best practices for writing efficient extensions. See a list of [VSSDK analyzers](https://github.com/Microsoft/VSSDK-Analyzers/blob/main/doc/index.md) and [threading analyzers](https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/index.md).
151+
You can also use the new Visual Studio static analyzers for extensions (NuGet package [here](https://www.nuget.org/packages/microsoft.visualstudio.sdk.analyzers)), that provide guidance on best practices for writing efficient extensions. See a list of [VSSDK analyzers](https://github.com/Microsoft/VSSDK-Analyzers/blob/main/doc/index.md) and [threading analyzers](https://github.com/microsoft/vs-threading/blob/main/docfx/analyzers/index.md).
152152

153153
> [!NOTE]
154154
> If you are unable to address the unresponsiveness due to dependencies you do not have control over (for example, if your extension has to call synchronous VS services on the UI thread), we would like to know about it. If you are a member of our Visual Studio Partner program, you can contact us by submitting a developer support request. Otherwise, use the 'Report a Problem' tool to submit your feedback and include `"Extension UI Delay Notifications"` in the title. Please also include a detailed description of your analysis.

docs/ide/ai-assisted-development-visual-studio.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ The following table compares the capabilities of GitHub Copilot (and GitHub Copi
9595
9696
| **AI-assistance feature** | **GitHub Copilot** | **IntelliCode** |
9797
|---------------------------|:--------------------:|:-----------------:|
98-
| Available as | - [Built-in by default in all workloads](visual-studio-github-copilot-install-and-states.md#get-github-copilot-for-visual-studio-2022-version-1710-or-later) & available through the Visual Studio Installer in Visual Studio version 17.10 and later <br/> - [Downloadable extensions](visual-studio-github-copilot-install-and-states.md#get-github-copilot-for-visual-studio-2022-versions-178-to-179) in Visual Studio versions 17.8 & 17.9| Built-in by default in most [workloads](../install/modify-visual-studio.md#change-workloads-or-individual-components) & available through the Visual Studio Installer |
98+
| Available as |[Built-in by default in all workloads](visual-studio-github-copilot-install-and-states.md#install-using-the-visual-studio-installer) & available through the Visual Studio Installer in Visual Studio version 17.10 and later <br/>| Built-in by default in most [workloads](../install/modify-visual-studio.md#change-workloads-or-individual-components) & available through the Visual Studio Installer |
9999
| Subscription-based | **Yes** <br/>[Learn more](https://docs.github.com/en/billing/managing-billing-for-github-copilot/about-billing-for-github-copilot)| No |
100100
| User interface | Inline <br/>Chat window | Inline |
101101
| Context-aware AI-assisted [IntelliSense](using-intellisense.md) | **Yes** <br/>[Learn more](visual-studio-github-copilot-extension.md#exploring-github-copilot) | **Yes** <br/>[Learn more](#intellicode-in-visual-studio) |

0 commit comments

Comments
 (0)