- Behavioral Contract
- Structural Contract
- Service Contract
- Operation Contract
- Fault Contract
- Data Contract
- Message Contract
Either only messagecontract can be used as parameter and return value or nothing as parameter or return type.
Term
|
Web Service
|
WCF service
|
Protocol
|
Http only
|
Http, TCP, MSMQ, NamedPipe
|
Security
|
Limited (Protocol security only)
|
Vast (Protocol, transactions, secure messaging)
|
Hosting
|
IIS only
|
IIS, WAS, Self-hosting
|
Serializer
|
XML only
|
Data contract serializer
|
Duplex
|
One way
|
Two way request response (Duplex)
|
WCF bindings
|
||||||
Binding
|
Protocol/
Transport
|
Message Encoding
|
Security
|
Default Session
|
Transaction
|
Duplex
|
BasicHttpBinding
|
Http, Https
|
Text
|
None
|
No
|
-
|
-
|
WSHttpBinding
|
Http, Https
|
Text
|
Message
|
Optional
|
Yes
|
-
|
WSDualHttpBinding
|
Http, Https
|
Text
|
Message
|
Yes
|
Yes
|
Yes
|
NetTcpBinding
|
TCP
|
Binary
|
Transport
|
Optional
|
Yes
|
Yes
|
NetNamedPipeBinding
|
Named Pipe
|
Binary
|
Transport
|
Yes
|
Yes
|
Yes
|
NetMsmqBinding
|
MSMQ
|
Binary
|
Transport
|
Yes
|
Yes
|
No
|
WSFederationHttpBinding
|
Http, Https
|
Text
|
Message
|
Yes
|
Yes
|
No
|
NetPeerTcpBinding
|
P2P
|
Binary
|
Transport
|
-
|
-
|
Yes
|
async / await in .NET?In simple terms:
asyncandawaitenable asynchronous, non-blocking programming in .NET.
They allow your app to perform long-running tasks (like database calls, file I/O, or API calls) without freezing the main thread.
Imagine a web API endpoint that calls a database and waits for the response.
If this were synchronous, that thread would just sit idle waiting — wasting server resources.
But with async/await, the thread is released back to the thread pool while waiting.
That means:
Better scalability — more requests can be handled.
No UI freeze (in desktop apps).
Efficient use of system threads.
| Concept | Description |
|---|---|
async keyword | Marks a method as asynchronous — allows use of await inside it. |
await keyword | Suspends the method until the awaited task completes, without blocking the thread. |
Task | Represents an ongoing operation (future result). |
Task<T> | Represents an async operation that returns a result. |
void async methods | Only used for event handlers — otherwise avoid. |
public string GetData()
{
var data = File.ReadAllText("data.txt"); // blocks until done
return data;
}
public async Task<string> GetDataAsync()
{
var data = await File.ReadAllTextAsync("data.txt"); // non-blocking
return data;
}
✅ While waiting for File.ReadAllTextAsync() to finish,
the current thread is released to handle other work.
[HttpGet("user/{id}")]
public async Task<IActionResult> GetUser(int id)
{
var user = await _userRepository.GetUserByIdAsync(id);
return Ok(user);
}
Here:
The thread executing this request can return to the thread pool while waiting on the DB.
Once the task completes, .NET resumes the method and sends the response.
This allows ASP.NET Core to handle many concurrent requests efficiently.
Request → Controller → await Repository call → Thread released
↓
DB operation completes
↓
Continuation resumes → Response sent
When the compiler sees async and await, it:
Transforms the method into a state machine.
Handles continuations automatically (what happens after the task completes).
Avoids the need for callbacks or manual threading.
✅ Use async all the way down (from controller → repository → I/O).
✅ Return Task or Task<T> (not void).
✅ Use ConfigureAwait(false) in library code (not needed in ASP.NET Core usually).
✅ Avoid blocking calls like .Result or .Wait() — they can cause deadlocks.
✅ Combine async calls efficiently using Task.WhenAll().
| Aspect | Synchronous | Asynchronous |
|---|---|---|
| Thread | Blocked until work completes | Freed while waiting |
| Performance | Scales poorly under load | Scales efficiently |
| Keyword | None | async / await |
| Return type | T | Task<T> |
| Use case | Quick operations | I/O-bound operations |
If your ASP.NET Core Web API calls:
AWS DynamoDB
S3 file upload
SNS message publish
All those SDKs have async methods (e.g., PutItemAsync, UploadAsync, PublishAsync).
Using await makes them non-blocking, improving throughput.
๐งฉ Difference between Task and Task<T>
| Feature | Task | Task<T> |
|---|---|---|
| Return Type | Represents an asynchronous operation that does not return a value. | Represents an asynchronous operation that returns a result of type T. |
| Equivalent to (sync) | Like void in synchronous methods. | Like returning a value of type T in synchronous methods. |
| Usage | When the method performs work but doesn’t need to return a value. | When the method performs work and returns a value asynchronously. |
| Example Method Signature | public async Task DoWorkAsync() | public async Task<int> GetCountAsync() |
| How to Await | await DoWorkAsync(); | int count = await GetCountAsync(); |
| When to Use | Fire-and-forget tasks (but still awaitable) like logging, sending email, etc. | Database calls, HTTP requests, file reads, calculations, etc. |
| Completion Handling | Only completion (success/failure) | Completion plus a result value |
Task (no return value)public async Task SendEmailAsync(string to)
{
await emailService.SendAsync(to, "Welcome!", "Thanks for joining us!");
}
Usage:
await SendEmailAsync("user@example.com");
✅ You’re waiting for completion — but there’s no result to retrieve.
Task<T> (returns a value)public async Task<int> GetUserCountAsync()
{
return await _dbContext.Users.CountAsync();
}
Usage:
int count = await GetUserCountAsync();
✅ You’re waiting for the task to complete and getting back a result (int).
Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...