0
votes

I am trying to build an Azure Function to process Dynamics 365 messages from an Azure Service Bus. The message is serialized in the .NET Binary XML format, so I am trying to receive the message as binary and deserialize it in my code.

The signature of my function method is:

public static void Run(
    [ServiceBusTrigger("queue", Connection = "...")] byte[] message,
    ILogger log,
    MessageReceiver messageReceiver)

However the functions runtime still fails while trying to parse message, as I get following error:

The Message with ContentType 'application/msbin1' failed to deserialize to a string with the message: 'Expecting element 'string' from namespace 'http://schemas.microsoft.com/2003/10/Serialization/'.. Encountered 'Element' with name 'RemoteExecutionContext', namespace 'http://schemas.microsoft.com/xrm/2011/Contracts'.'. System.Private.DataContractSerialization: Expecting element 'string' from namespace 'http://schemas.microsoft.com/2003/10/Serialization/'.. Encountered 'Element' with name 'RemoteExecutionContext', namespace 'http://schemas.microsoft.com/xrm/2011/Contracts'.

How can I receive raw data using ServiceBusTrigger?

EDIT 1: The same error occurs with

public static void Run(
    [ServiceBusTrigger("queue", Connection = "...")] Message message,
    ILogger log)

I use following versions Microsoft.Azure.WebJobs.Extensions.ServiceBus 4.1.0 and Microsoft.NET.Sdk.Functions 3.0.7.

EDIT 2:
Updated versions to Microsoft.Azure.WebJobs.Extensions.ServiceBus 4.1.1 and Microsoft.NET.Sdk.Functions 3.0.11 the error is gone, but message length is 0 bytes for both byte[] and Message.Content

EDIT 3:

Azure Functions Core Tools
Core Tools Version:       3.0.3160 Commit hash: 00aa7f43cc5c5f15241b5e6e5363256f19ceb990
Function Runtime Version: 3.0.14916.0
2
If you set the type to Message instead of byte[] do you get the same error? the Massage.Body property should contain the byte array but avoid having Functions try to access the message as it sounds like it is having trouble with that. It would also be helpful to make sure the Functions SDK is up to date and share that version number if you could- if it is on the latest version that will help with reproing the issue. - SamaraSoucy

2 Answers

0
votes

ContentType needs to be application/json. See this GitHub issue for the details.

0
votes

Make sure your message format is JSON and NOT .NETBinary

enter image description here