Neuron ESB User Network

The Service Bus for the Connected Business

How do I use the DataContractSerializer in message.GetBody<>()

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

Views: 528

Reply to This

Replies to This Discussion

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);
}
}
}

Attachments:

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">

RSS

Neuron ESB Product Support Forums and Communities

Latest Activity

Anupama Nair posted a discussion

Marketo Adapter Invalid Token

Hi,We are using the Marketo adapter to push account updates to Marketo. It works well for some time then starts failing with Invalid Token unless restarted. Is there a configuration that can be done so it can auto refresh the token when required?Thanks!See More
Nov 6, 2023
Sayantini Basak posted a discussion

Maximum payload size(REST API) for requests interfacing to NeuronESB

I am new to Neuron ESB and in our current scenario,We need to process batch transactions comprising of ~1000 records and send them to Neuron ESB for further processing. I would like to understand what is the maximum size of payload that can be transferred using REST interface to Neuron ESB.See More
Jul 22, 2022
Profile IconRobert E Dunie and Sayantini Basak joined Neuron ESB User Network
Apr 28, 2022
Profile IconDayanand, Frederic C, Steffen Greve-Oksfeldt and 1 more joined Neuron ESB User Network
Mar 16, 2022
Profile IconCam Vong and Mitja Luznar joined Neuron ESB User Network
Jan 27, 2022
Profile IconWill Hitzges, Chad Parsons, michael larsen and 4 more joined Neuron ESB User Network
Jun 11, 2021
Anupama Nair posted a discussion

ODBC stored proc polling with temporary tables

We have set up an ODBC adapter to poll a stored proc.We found that if the stored proc has a temporary table defined the rows returned are always 0.Any idea why this would be and what we can do to get around it?See More
Dec 14, 2020
Prasanth Kharade is now a member of Neuron ESB User Network
Dec 30, 2019

Badge

Loading…

© 2024   Created by Neuron Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service