Hello,
I'm trying to deserialize webhook body - RemoteExecutionContext. I use preferred DataContractJsonSerializer. Unfortunately deserialization fails for all datetime fields and some optionsets. I've tryied to use JObject, get postImage and then use toObject<>() deserialization, that fails on some attributes value deserialization. I´ve tried Newtonsoft.Json and System.Text.Json deserialization for RemoteExecutionContext, both fails.
Input values in postimage in json:
Datetime:
OptionSet which fails in deserialization:
Code to get entity from webhook:
public override ResponseDetail DoProcess(CrmMessageHeader header, string data) { if (header.LoadFromCrm || data == null) throw new ApiException("Entity data not provided"); var crmWebhookContext = DataContractJsonSerializerHelper.Deserialize(data); var carnet = crmWebhookContext.GetPostImage().ToEntity(); ..... }
DataContractJsonSerializerHelper Deserialize:
public static class DataContractJsonSerializerHelper { public static TObject Deserialize(string jsonString) { var settings = new JsonSerializerSettings { Converters = { new DataContractDateTimeOffsetConverter(true) }, }; var obj = Activator.CreateInstance(); var ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)); var serializer = new DataContractJsonSerializer(obj.GetType()); obj = (TObject)serializer.ReadObject(ms); ms.Close(); return obj; }
RemoteExecutionContextExtension GetPostImage:
public static class RemoteExecutionContextExtensions { public static Entity GetPostImage(this RemoteExecutionContext context, string name = "image") { if (!context.PostEntityImages.Contains(name)) throw new ApiException($"CrmWebHook does not contains PostImageEntity {name}"); return context.PostEntityImages[name]; }
Result in entity:
Result in deserialized RemoteExecutionContext:
In RemoteExecutionContext are the values already deserialized wrong. We would like to use generic method for deserialization and not for every webhook type parse values from attributes. Have anyone any idea?
Thank you in advance.
Daniel
Hi,
I remember using code from below article to deserialize RemoteExecutionContext
Once you get RemoteExecutionContext object then get post entity image and store it into Entity object
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Eugen Podkorytov
106
Muhammad Shahzad Sh...
106
Most Valuable Professional