Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions Documentation/using-clients.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
#Using Generated Clients
#Using Generated Clients (C#)

##Contents

TODO


##Overview
AutoRest generates a client type based on a name defined in the specification (see [swagger specification parsing](swagger.md) overview). The generated client inherits from [`ServiceClient<T>`](../Microsoft.Rest/ClientRuntime/ServiceClient.cs).
AutoRest generated code can currently work in a variety of .NET project types including:

* Desktop applications (.NET 4.0 and .NET 4.5)
* Web applications (.NET 4.0 and .NET 4.5)
* Windows Phone (8.1)
* Windows Store App (8.1)
* Portable Class Libraries

Before being able to compile generated code *Microsoft.Rest.ClientRuntime* nuget package needs to be added to the project. This package will include several dependent packages based on project profile such as Newtonsoft Json.Net.

After that, the client can be used as such:
```
var myClient = new MyClient();
var salutation = myClient.GetGreeting();
Console.WriteLine(salutation);
```

##Initialization
AutoRest generates a client type based on a name defined in the specification (see [swagger specification parsing](swagger.md) overview). The generated client inherits from [`ServiceClient<T>`](../Microsoft.Rest/ClientRuntime/ServiceClient.cs) base type available in *Microsoft.Rest.ClientRuntime* nuget package.

Client is generated with a number of constructors:

* Default constructor that sets Base URL of the client to the one specified in the specification and configures the client to use anonymous authentication
* Constructor that accepts Base URL
* Constructor that accepts Credentials object (see [authentication](#Authentication) section)

##Authentication
The client will support authentication if it was generated using [-AddCredentials](cli.md) flag.

##Tracing
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using MyNamespace;
We now access the REST API with the fact that `GetGreeting` will throw an exception if the response is not a 200 OK, we can access the REST API with very little code (see [using generated clients](Documentation/using-clients.md) for details).
```
var myClient = new MyClient();
var salutation = myClient.GetGreeting().Body();
var salutation = myClient.GetGreeting();
Console.WriteLine(salutation);
```
Running the console app shows the greeting retrieved from the service API.
Expand Down