# XML Serializer sample This sample demonstrates the built-in NServiceBus XML serializer. ## Configuring to use XML ```cs var endpointConfiguration = new EndpointConfiguration("Samples.Serialization.Xml"); endpointConfiguration.UseSerialization(); // Then later get it from the service provider when needed builder.Services.AddSingleton(); var serviceProvider = builder.Services.BuildServiceProvider(); var messageBodyWriter = serviceProvider.GetRequiredService(); // register the mutator so the the message on the wire is written endpointConfiguration.RegisterMessageMutator(messageBodyWriter); ``` ## Diagnostic mutator A helper that will log the contents of any incoming message: ```cs public class MessageBodyWriter(ILogger logger) : IMutateIncomingTransportMessages { public Task MutateIncoming(MutateIncomingTransportMessageContext context) { var bodyAsString = Encoding.UTF8.GetString(context.Body.ToArray()); logger.LogInformation("Serialized Message Body:"); logger.LogInformation(bodyAsString); return Task.CompletedTask; } } ``` ## Sending the message ```cs var message = new CreateOrder { OrderId = 9, Date = DateTime.Now, CustomerId = 12, OrderItems = new List { new OrderItem { ItemId = 6, Quantity = 2 }, new OrderItem { ItemId = 5, Quantity = 4 }, } }; await messageSession.SendLocal(message); ``` ## Output ```xml 9 2015-09-15T13:33:28.7186624+10:00 12 6 2 5 4 ```