WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 2b998e2

Browse files
authored
Expand output binding invocation docs (#1652)
* Expand output binding invocation docs. Signed-off-by: Alexander Trauzzi <[email protected]> * Updates based on suggestions. Signed-off-by: Alexander Trauzzi <[email protected]> --------- Signed-off-by: Alexander Trauzzi <[email protected]>
1 parent 615613e commit 2b998e2

File tree

1 file changed

+41
-3
lines changed
  • daprdocs/content/en/dotnet-sdk-docs/dotnet-client

1 file changed

+41
-3
lines changed

daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,54 @@ Console.WriteLine("Published deposit event!");
157157

158158
### Interact with output bindings
159159

160+
When calling `InvokeBindingAsync`, you have the option to handle serialization and encoding yourself,
161+
or to have the SDK serialize it to JSON and then encode it to bytes for you.
162+
163+
{{% alert title="Important" color="warning" %}}
164+
Bindings differ in the shape of data they expect, take special note and ensure that the data you
165+
are sending is handled accordingly. If you are authoring both an output and an input, make sure
166+
that they both follow the same conventions for serialization.
167+
{{% /alert %}}
168+
169+
#### Manual serialization
170+
171+
For most scenarios, you're advised to use this overload of `InvokeBindingAsync` as it gives you clarity and control over
172+
how the data is being handled.
173+
174+
_In this example, the data is sent as the UTF-8 byte representation of the string._
175+
176+
```csharp
177+
using var client = new DaprClientBuilder().Build();
178+
179+
var request = new BindingRequest("send-email", "create")
180+
{
181+
// note: This is an example payload for the Twilio SendGrid binding
182+
Data = Encoding.UTF8.GetBytes("<h1>Testing Dapr Bindings</h1>This is a test.<br>Bye!"),
183+
Metadata =
184+
{
185+
{ "emailTo", "[email protected]" },
186+
{ "subject", "An email from Dapr SendGrid binding" },
187+
},
188+
}
189+
await client.InvokeBindingAsync(request);
190+
```
191+
192+
#### Automatic serialzation and encoding
193+
194+
_In this example, the data is sent as a UTF-8 encoded byte representation of the value serialized to JSON._
195+
160196
```csharp
161-
// Example payload for the Twilio SendGrid binding
197+
using var client = new DaprClientBuilder().Build();
198+
162199
var email = new
163200
{
201+
// note: This is an example payload for the Twilio SendGrid binding
202+
data = "<h1>Testing Dapr Bindings</h1>This is a test.<br>Bye!",
164203
metadata = new
165204
{
166205
emailTo = "[email protected]",
167206
subject = "An email from Dapr SendGrid binding",
168-
},
169-
data = "<h1>Testing Dapr Bindings</h1>This is a test.<br>Bye!",
207+
},
170208
};
171209
await client.InvokeBindingAsync("send-email", "create", email);
172210
```

0 commit comments

Comments
 (0)