-
Notifications
You must be signed in to change notification settings - Fork 0
C# client
Using DTOs to define your web service interface makes it possible to provide strong-typed generic service clients without any code-gen or extra build-steps, leading to a productive end-to-end type-safe communication gateway from client to server.
All REST and ServiceClients share the same interfaces (IServiceClient
, IRestClient
and IRestClientAsync
) so they can easily be replaced (for increased perf/debuggability/etc) with a single line of code.
Here's a list of all built-in clients:
-
IServiceClient
- Soap11ServiceClient (uses SOAP 11 endpoint)
- Soap12ServiceClient (uses SOAP 12 endpoint)
- JsonServiceClient (uses default endpoint with JSON)
- JsvServiceClient (uses default endpoint with JSV)
- XmlServiceClient (uses default endpoint with XML)
-
IRestClient
- JsonServiceClient (uses custom REST endpoint with JSON) - recommended
- JsvServiceClient (uses custom REST endpoint with JSV)
- XmlServiceClient (uses custom REST endpoint with XML)
-
IRestClientAsync
- JsonRestClientAsync (uses custom REST endpoint with JSON) - recommended
- JsvRestClientAsync (uses custom REST endpoint with JSV)
- XmlRestClientAsync (uses custom REST endpoint with XML)
C#/.NET Clients can call the above Hello Service using any of the JSON, JSV, XML or SOAP Service Clients with the code below:
Using the New Api
var response = client.Send(new Hello { Name = "World!" });
response.Result.Print();
Async Example
client.SendAsync(new Hello { Name = "World!" },
r => r.Result.Print(), (r, ex) => { throw ex; });
var response = client.Send<HelloResponse>(new Hello { Name = "World!" });
response.Result.Print();
Async Example
client.SendAsync<HelloResponse>(new Hello { Name = "World!" },
r => r.Result.Print(), (r, ex) => { throw ex; });
The service clients use the automatic pre-defined routes for each service.
In addition, the service clients also provide HTTP verbs (Get, Post & PostFile, Put, Delete) letting you call your custom user-defined routes REST-fully e.g:
Using the New Api
HelloResponse response = client.Get("/hello/World!");
response.Result.Print();
Async Example
client.GetAsync("/hello/World!",
r => r.Result.Print(), (r, ex) => { throw ex; });
var response = client.Get<HelloResponse>("/hello/World!");
response.Result.Print();
Async Example
client.GetAsync<HelloResponse>("/hello/World!",
r => r.Result.Print(), (r, ex) => { throw ex; });
- Why ServiceStack?
- What is a message based web service?
- Advantages of message based web services
- Why remote services should use separate DTOs
- Getting Started
- Reference
- Clients
- Formats
- View Engines 4. Razor & Markdown Razor
- Hosts
- Advanced
- Configuration options
- Access HTTP specific features in services
- Logging
- Serialization/deserialization
- Request/response filters
- Filter attributes
- Concurrency Model
- Built-in caching options
- Built-in profiling
- Messaging and Redis
- Form Hijacking Prevention
- Auto-Mapping
- HTTP Utils
- Virtual File System
- Config API
- Physical Project Structure
- Modularizing Services
- Plugins
- Tests
- Other Languages
- Use Cases
- Performance
- How To
- Future