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
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.
Copy file name to clipboardExpand all lines: docs/core/additional-tools/dotnet-svcutil-guide.md
+71-21Lines changed: 71 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: WCF svcutil tool overview
3
3
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.
4
4
author: mlacouture
5
-
ms.date: 08/20/2018
5
+
ms.date: 02/22/2019
6
6
ms.custom: "seodec18"
7
7
---
8
8
# 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
18
18
19
19
## Prerequisites
20
20
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
22
23
* Your favorite code editor
23
24
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
+
24
31
## Getting started
25
32
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:
27
34
28
35
```csharp
29
36
[ServiceContract]
@@ -34,7 +41,7 @@ public interface ISayHello
34
41
}
35
42
```
36
43
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`
38
45
39
46
From a Windows, macOS, or Linux command window perform the following steps:
40
47
@@ -45,73 +52,116 @@ mkdir HelloSvcutil
45
52
cd HelloSvcutil
46
53
```
47
54
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
+
```
49
60
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)
50
63
```console
51
-
dotnet new console
64
+
dotnet tool install --global dotnet-svcutil
52
65
```
53
66
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:
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:
63
77
64
78
```console
65
79
dotnet restore
66
80
```
67
81
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
+
```
69
89
90
+
# [dotnet-svcutil 1.x](#tab/dotnetsvcutil1x)
70
91
```console
71
92
dotnet svcutil http://contoso.com/SayHello.svc
72
93
```
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.
74
97
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:
76
101
77
102
```console
78
103
dotnet restore
79
104
```
80
105
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:
82
109
83
110
```csharp
84
-
staticvoidMain(string[] args)
111
+
usingServiceReference;
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:
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:
92
135
93
136
```console
94
137
dotnet run
95
138
```
139
+
140
+
6. Navigate to the URL listed in the console (for example, `http://localhost:5000`) in your web browser.
141
+
96
142
You should see the following output:
97
143
"Hello dotnet-svcutil!"
98
144
99
145
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
+
```
100
150
151
+
# [dotnet-svcutil 1.x](#tab/dotnetsvcutil1x)
101
152
```console
102
153
dotnet svcutil --help
103
154
```
155
+
---
104
156
105
-
## Next steps
106
-
107
-
### Feedback & questions
157
+
## Feedback & questions
108
158
109
159
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).
110
160
111
-
###Release notes
161
+
## Release notes
112
162
113
163
* 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.
0 commit comments