none
Azure ServiceBusTrigger not accepting custom data type as input binding parameter RRS feed

  • Question

  • Function signature :

       public static async void Run([ServiceBusTrigger("MyTopic", "SubscriptionName", Connection = "ServiceBusConnectionString")]Customer customer, ILogger log)

    Error:

    [8/27/2018 8:45:08 PM] System.Private.CoreLib: Exception while executing function:
     XXXXXX. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'customer'. System.Private.DataContractSerialization: 
     There was an error deserializing the object of type LBSalesOrderStatus.Functions.GeneratedTypes.SalesOrderStatus. The input source is not correctly formatted. 

    The customer object is a generated c# class from an XSD and its using XML serialization. We generated C# class with data contract serialization by using SvcUtil.exe as well. However, the error is same. 

    The XML message on the service bus is valid. We tried the following the following and it works very well.

    var customer = DeserializeFromXmlString<Customer>(Encoding.UTF8.GetString(message.Body));

    The function is using .NET core based run time and we are using the service bus NuGet package "Microsoft.Azure.ServiceBus"

    Monday, August 27, 2018 10:28 PM

Answers

  • For this deserialization to work, the message would have to be in JSON format. Since your messages are currently in XML you will need to change your function code to receive the message as a string and do the deserialize yourself using the code you shared.
    • Marked as answer by ssashok10 Tuesday, August 28, 2018 1:39 PM
    • Unmarked as answer by ssashok10 Tuesday, August 28, 2018 1:39 PM
    • Marked as answer by ssashok10 Tuesday, August 28, 2018 1:39 PM
    Monday, August 27, 2018 10:42 PM

All replies

  • For this deserialization to work, the message would have to be in JSON format. Since your messages are currently in XML you will need to change your function code to receive the message as a string and do the deserialize yourself using the code you shared.
    • Marked as answer by ssashok10 Tuesday, August 28, 2018 1:39 PM
    • Unmarked as answer by ssashok10 Tuesday, August 28, 2018 1:39 PM
    • Marked as answer by ssashok10 Tuesday, August 28, 2018 1:39 PM
    Monday, August 27, 2018 10:42 PM
  • Thanks for the quick response.
    Tuesday, August 28, 2018 1:39 PM