I'm using Neuron 3.1.0.275. I'm trying to create a custom adapter. In the SendToEndpoint method I am trying to extract the message body using the following:
var messageBody = message.GetBody<Contracts.TransmissionRequest>();
TransmssionRequest is decorated with the DataContract attribute and it's properties are decorated with the DataMember attribute.
When I use the Neuron Test Client to send an object the GetBody call exceptions because one of the TransmissionRequest properties implements IDictionary. I understand that the xml serializer doesn't serialize IDictionary and there is plenty of knowledge around the Internet to solve that. My question is how do I force the DataContractSerializer to be used?
The documentation for the ESBMessage.Body property states:
Objects will be serialized in the following manner:
Any help would be appreciated.
Tags: adapter, datacontract, messaging, serialization
Hi Jon. Can you share the source code for TransmissionRequest so that I can try to reproduce the issue in my development environment? If you don't want to share it publicly, you can email it to me at neuronsupport@neudesic.com.
Thanks
Michael Collins
Neuron Support
Here is the calling code from the Adapter. The TransmissionRequest is attached. The RaiseAdapterLog method is a custom method because the RaiseAdapterInfo and RaiseAdapterError methods from ESBAdapterBase don't write to the Windows event log.
public override async void SendToEndpoint(ESBMessage message, CommittableTransaction tx)
{
try
{
RaiseAdapterLog(ErrorLevel.Info, "Before GetBody");
RaiseAdapterLog(ErrorLevel.Info, message.Text);
var messageBody = message.GetBody<Contracts.TransmissionRequest>();
RaiseAdapterLog(ErrorLevel.Info, "After GetBody");
var transmissionRequest = Mapper.Map<Adapter.TransmissionRequest>(messageBody);
var result = await SendMessageAsync(transmissionRequest);
if (message.Header.Semantic == Semantic.Request)
{
var replyMessage = message.CreateReplyMessage();
replyMessage.FromString(result);
RaiseReceiveFromEndpointEvent(replyMessage);
}
else
{
var responseMessage = new ESBMessage(this.PublishTopic, result);
RaiseReceiveFromEndpointEvent(responseMessage);
}
}
catch (Exception ex)
{
string errorMessage = "Error in SendToEndpoint - Details: " + GetExceptionMessages(ex);
RaiseAdapterLog(ErrorLevel.Error, errorMessage);
if (message.Header.Semantic == Semantic.Request)
{
var replyMessage = message.CreateReplyMessage();
replyMessage.FromString(errorMessage);
RaiseReceiveFromEndpointEvent(replyMessage);
}
else
{
var responseMessage = new ESBMessage(this.PublishTopic, errorMessage);
RaiseReceiveFromEndpointEvent(responseMessage);
}
}
}
1. Can you copy/paste the exception into a reply so that I can see the error?
2. For the collection types (IDictionary and IEnumerable), what are the concrete types that you are using for the collections?
I tried a simple program using your data contracts, but it's working for me and I can see that the DataContractSerializer is being used:
class Program
{
static void Main()
{
var transmissionRequest = new TransmissionRequest
{
ClickTracking = true,
EnvironmentFrom = "test",
Metadata = new Dictionary<string, string> { { "hello", "world!" }, { "goodbye", "world!" } },
OpenTracking = true,
Recipients = new List<Recipient>
{
new Recipient
{
Metadata = new Dictionary<string, string>(),
RecipientAddress = new RecipientAddress { EmailId = "1", EnvironmentFrom = "test" },
SubstitutionData = new Dictionary<string, string>(),
Tags = new List<string> { "hello", "test" }
}
},
SubstitutionData = new Dictionary<string, string> { { "substitute", "me" } },
TemplateContent = new EmailMessage()
};
var message = new ESBMessage(transmissionRequest);
var newTransmissionRequest = message.GetBody<TransmissionRequest>();
}
}
It's working now. I missed the xml namespace in the message I was sending.
<TransmissionRequest xmlns="http://schemas.outsell.com/services/transmission/2014/10/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
Neuron ESB Product Support Forums and Communities
© 2024 Created by Neuron Admin. Powered by