Skip to content

Commit dfb238a

Browse files
dasetsermairaw
authored andcommitted
Updating dotnet-svcutil guide for version 2.0. (dotnet#10506)
* Updating dotnet-svcutil guide for version 2.0. * Adding tabs with instructions for previous version, and changing the example from a console app to a web app. * Fixing incorrect numbering. * Apply suggestions from code review Co-Authored-By: dasetser <dasetser@microsoft.com> * Addressing review feedback.
1 parent 3a4a507 commit dfb238a

File tree

1 file changed

+71
-21
lines changed

1 file changed

+71
-21
lines changed

docs/core/additional-tools/dotnet-svcutil-guide.md

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: WCF svcutil tool overview
33
description: An overview of the Microsoft WCF dotnet-svcutil tool that adds functionality for .NET Core and ASP.NET Core projects, similar to the WCF svcutil tool for .NET Framework projects.
44
author: mlacouture
5-
ms.date: 08/20/2018
5+
ms.date: 02/22/2019
66
ms.custom: "seodec18"
77
---
88
# WCF dotnet-svcutil tool for .NET Core
@@ -18,12 +18,19 @@ The **dotnet-svcutil** tool is an alternative option to the [**WCF Web Service R
1818
1919
## Prerequisites
2020

21-
* [.NET Core SDK](https://dotnet.microsoft.com/download) v1.0.4 or later versions
21+
# [dotnet-svcutil 2.x](#tab/dotnetsvcutil2x)
22+
* [.NET Core 2.1 SDK](https://dotnet.microsoft.com/download) or later versions
2223
* Your favorite code editor
2324

25+
# [dotnet-svcutil 1.x](#tab/dotnetsvcutil1x)
26+
* [.NET Core 1.0.4 SDK](https://dotnet.microsoft.com/download) or later versions
27+
* Your favorite code editor
28+
29+
---
30+
2431
## Getting started
2532

26-
The following example walks you through the steps required to add a web service reference to a .NET Core console project and invoke the service. You will create a .NET Core console application named _HelloSvcutil_ and will add a reference to a web service that implements the following contract:
33+
The following example walks you through the steps required to add a web service reference to a .NET Core web project and invoke the service. You'll create a .NET Core web application named _HelloSvcutil_ and add a reference to a web service that implements the following contract:
2734

2835
```csharp
2936
[ServiceContract]
@@ -34,7 +41,7 @@ public interface ISayHello
3441
}
3542
```
3643

37-
For this example, the web service will be assumed to be hosted at the following address: `http://contoso.com/SayHello.svc`
44+
For this example, let's assume the web service will be hosted at the following address: `http://contoso.com/SayHello.svc`
3845

3946
From a Windows, macOS, or Linux command window perform the following steps:
4047

@@ -45,73 +52,116 @@ mkdir HelloSvcutil
4552
cd HelloSvcutil
4653
```
4754

48-
2. Create a new C# console project in that directory using the [`dotnet new`](../tools/dotnet-new.md) command as follows:
55+
2. Create a new C# web project in that directory using the [`dotnet new`](../tools/dotnet-new.md) command as follows:
56+
57+
```console
58+
dotnet new web
59+
```
4960

61+
3. Install the [`dotnet-svcutil` NuGet package](https://nuget.org/packages/dotnet-svcutil) as a CLI tool:
62+
# [dotnet-svcutil 2.x](#tab/dotnetsvcutil2x)
5063
```console
51-
dotnet new console
64+
dotnet tool install --global dotnet-svcutil
5265
```
5366

54-
3. Open the `HelloSvcutil.csproj` project file in your editor, edit the `Project` element, and add the [`dotnet-svcutil` NuGet package](https://nuget.org/packages/dotnet-svcutil) as a CLI tool reference, using the following code:
67+
# [dotnet-svcutil 1.x](#tab/dotnetsvcutil1x)
68+
Open the `HelloSvcutil.csproj` project file in your editor, edit the `Project` element, and add the [`dotnet-svcutil` NuGet package](https://nuget.org/packages/dotnet-svcutil) as a CLI tool reference, using the following code:
5569

5670
```xml
5771
<ItemGroup>
5872
<DotNetCliToolReference Include="dotnet-svcutil" Version="1.0.*" />
5973
</ItemGroup>
6074
```
6175

62-
4. Restore the _dotnet-svcutil_ package using the [`dotnet restore`](../tools/dotnet-restore.md) command as follows:
76+
Then restore the _dotnet-svcutil_ package using the [`dotnet restore`](../tools/dotnet-restore.md) command as follows:
6377

6478
```console
6579
dotnet restore
6680
```
6781

68-
5. Run _dotnet_ with the _svcutil_ command to generate the web service reference file as follows:
82+
---
83+
84+
4. Run the _dotnet-svcutil_ command to generate the web service reference file as follows:
85+
# [dotnet-svcutil 2.x](#tab/dotnetsvcutil2x)
86+
```console
87+
dotnet-svcutil http://contoso.com/SayHello.svc
88+
```
6989

90+
# [dotnet-svcutil 1.x](#tab/dotnetsvcutil1x)
7091
```console
7192
dotnet svcutil http://contoso.com/SayHello.svc
7293
```
73-
The generated file is saved as _HelloSvcutil/ServiceReference1/Reference.cs_. The _dotnet_svcutil_ tool also adds to the project the appropriate WCF packages required by the proxy code as package references.
94+
---
95+
96+
The generated file is saved as _HelloSvcutil/ServiceReference/Reference.cs_. The _dotnet-svcutil_ tool also adds to the project the appropriate WCF packages required by the proxy code as package references.
7497

75-
6. Restore the WCF packages using the [`dotnet restore`](../tools/dotnet-restore.md) command as follows:
98+
## Using the Service Reference
99+
100+
1. Restore the WCF packages using the [`dotnet restore`](../tools/dotnet-restore.md) command as follows:
76101

77102
```console
78103
dotnet restore
79104
```
80105

81-
7. Open the `Program.cs` file in your editor, edit the `Main()` method, and replace the auto-generated code with the following code to invoke the web service:
106+
2. Find the name of the client class and operation you want to use. `Reference.cs` will contain a class that inherits from `System.ServiceModel.ClientBase`, with methods that can be used to call operations on the service. In this example, you want to call the _SayHello_ service's _Hello_ operation. `ServiceReference.SayHelloClient` is the name of the client class, and has a method called `HelloAsync` that can be used to call the operation.
107+
108+
3. Open the `Startup.cs` file in your editor, and add a using statement for the service reference namespace at the top:
82109

83110
```csharp
84-
static void Main(string[] args)
111+
using ServiceReference;
112+
```
113+
114+
4. Edit the `Configure` method to invoke the web service. You do this by creating an instance of the class that inherits from `ClientBase` and calling the method on the client object:
115+
116+
```csharp
117+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
85118
{
86-
var client = new SayHelloClient();
87-
Console.WriteLine(client.HelloAsync("dotnet-svcutil").Result);
119+
if (env.IsDevelopment())
120+
{
121+
app.UseDeveloperExceptionPage();
122+
}
123+
124+
app.Run(async (context) =>
125+
{
126+
var client = new SayHelloClient();
127+
var response = await client.HelloAsync();
128+
await context.Response.WriteAsync(response);
129+
});
88130
}
131+
89132
```
90133

91-
8. Run the application using the [`dotnet run`](../tools/dotnet-run.md) command as follows:
134+
5. Run the application using the [`dotnet run`](../tools/dotnet-run.md) command as follows:
92135

93136
```console
94137
dotnet run
95138
```
139+
140+
6. Navigate to the URL listed in the console (for example, `http://localhost:5000`) in your web browser.
141+
96142
You should see the following output:
97143
"Hello dotnet-svcutil!"
98144

99145
For a detailed description of the `dotnet-svcutil` tool parameters, invoke the tool passing the help parameter as follows:
146+
# [dotnet-svcutil 2.x](#tab/dotnetsvcutil2x)
147+
```console
148+
dotnet-svcutil --help
149+
```
100150

151+
# [dotnet-svcutil 1.x](#tab/dotnetsvcutil1x)
101152
```console
102153
dotnet svcutil --help
103154
```
155+
---
104156

105-
## Next steps
106-
107-
### Feedback & questions
157+
## Feedback & questions
108158

109159
If you have any questions or feedback, [open an issue on GitHub](https://github.com/dotnet/wcf/issues/new). You can also review any existing questions or issues [at the WCF repo on GitHub](https://github.com/dotnet/wcf/issues?utf8=%E2%9C%93&q=is:issue%20label:tooling).
110160

111-
### Release notes
161+
## Release notes
112162

113163
* Refer to the [Release notes](https://github.com/dotnet/wcf/blob/master/release-notes/dotnet-svcutil-notes.md) for updated release information, including known issues.
114164

115-
### Information
165+
## Information
116166

117167
* [dotnet-svcutil NuGet Package](https://nuget.org/packages/dotnet-svcutil)

0 commit comments

Comments
 (0)