ServiceEndpoint注册中.NetBinary消息格式的具体作用咨询
Great question—this is one of those niche but critical details when routing PluginExecutionContext to Azure services via Dynamics 365 service endpoints. Let me break down exactly what this format is, how it compares to JSON, and when you’d want to use it.
What is .NetBinary Format?
At its core, .NetBinary is Microsoft’s native binary serialization format for .NET objects. For Dynamics 365 scenarios, it uses the System.Runtime.Serialization.DataContractSerializer to convert the full PluginExecutionContext object (and all its nested properties like Entity records, OptionSetValue instances, etc.) into a compact binary byte stream.
Unlike JSON (the text-based format you’re using now), this format preserves every detail of the original .NET type—including inheritance hierarchies, private field metadata, and strong type markers that JSON often drops or converts to generic values.
How It Works with ServiceEndpoints
When you select .NetBinary as the message format in the Plugin Registration Tool:
- Dynamics 365 serializes the
PluginExecutionContextdirectly to a binary blob instead of converting it to JSON text. - This blob is sent to your Azure Queue (or Service Bus) as the message body.
- If your receiving service is a .NET application (like an Azure Function or Worker Service), you can deserialize the blob straight back into a fully functional
PluginExecutionContextobject without manual mapping.
Here’s a quick example of deserializing in an Azure Function:
using System.IO; using System.Runtime.Serialization; using Microsoft.Xrm.Sdk; public static void Run(byte[] myQueueItem, ILogger log) { // Initialize the serializer for PluginExecutionContext var serializer = new DataContractSerializer(typeof(PluginExecutionContext)); // Convert the binary message back to the context object using var memoryStream = new MemoryStream(myQueueItem); var executionContext = (PluginExecutionContext)serializer.ReadObject(memoryStream); // Use the context directly—no JSON parsing needed! log.LogInformation($"Received context for {executionContext.PrimaryEntityName} record: {executionContext.PrimaryEntityId}"); }
.NetBinary vs. JSON: Key Tradeoffs
| Aspect | .NetBinary | JSON |
|---|---|---|
| Performance | Faster serialization/deserialization, smaller payload size | Slower for large contexts, larger text payload |
| Type Fidelity | Preserves all .NET type details (no data loss) | Loses strong type info (e.g., OptionSetValue becomes a raw number) |
| Cross-Platform | .NET-only—hard to parse in non-.NET stacks (Java, Python, etc.) | Universal, easy to parse in any language |
| Ease of Debugging | Not human-readable—you can’t inspect the binary payload directly | Human-readable, easy to debug with tools like Postman |
When to Use .NetBinary
Opt for .NetBinary if:
- Your receiving service is built with .NET (so you can leverage direct object deserialization).
- You need maximum performance and minimal payload size for high-volume scenarios.
- You rely on the full, unmodified
PluginExecutionContexttype (including nested complex objects).
If you’re working with non-.NET services or need easy debuggability, sticking with JSON is the better call.
内容的提问来源于stack exchange,提问作者Paul Richardson

