Create WCF addressing headers for reply message - wcf

I have a generic service with this interface
[OeprationContract(Action="*", ReplyAction="*")]
Message ProcessMessage(Message message);
In the implementation, I have to set up the headers of the reply message.
Is there a way to create the right addressing headers from the input message or do I have to set everything manually (i.e. copy In.replyTo to out.To, copy In.messageId to out.MessageId, ...)
Thanks

You'll need to do it manually; when you declare an operation taking an returning a Message object you're basically telling WCF that you want total control over the message, so no correlation between request and reply will be done for you.

Related

Update body of a "FailedMessages"-document in ravendb (servicecontrol instance )

I want to be able to retry a failed NServicebus message but with an updated body.
I have successfulle updated the body tag in ravendb (the servicecontrol instance) of a "FailedMessages" Document
but
the api still returns the old body (from the bodyUrl). So when i retry the message from our custom document viewer the body is still the old when reaches the Handler.
Is it possible to update the body?
-EDIT-
When you do a retry using the Servicecontrol API. Is it the message that is in the error queue that is resent or is it data collected from the servicecontrol ravendb instance that are put together and sent?
It is not possible to update the body of a message, it goes against the basic principle of messages are immutable...
If there is a business reason to modify the data then it should be done by your application logic i.e. a reconciliation process.
Make sense?
EDIT:-
Error messages are processed from the error queue and stored in a RavenDB document, when a retry or a retry batch is invoked the message is composed and sent to the original endpoint that was processing the field message. Just to be clear.
Please note: ServiceControl's API is not a public and supported API...
I just managed to update the body of a message. It is possible after all.
Here is some sourcecode from ServiceControl:
DocumentStore.DatabaseCommands.PutAttachment("messagebodies/" + bodyId, null, bodyStream, new RavenJObject
{
{"ContentType", contentType},
{"ContentLength", bodySize}
});
Previously I tried to update the FailedMessage document which has a body tag. But I needed to update the Attachment. The bodyId in the above code is not the UniqueMessageId but MessageId found in ProcessingAttempts -> MessageMetadata -> MessageId.

NServicebus: reply message in case of exception

I have an endpoint which receives messages and creates a saga in order to be able to response to that corresponding message at a later point in time. The message contains some xml document and this xml doc will be validated within this message handler. If we catch some validation errors, we create a message response (no saga involved) to inform the originating endpoint that something with the xml doc was wrong. In the case of a validation error, the saga is not stored as expected and as required. But I still want to reply to the originating endpoint. The problem is, that nservicebus also does a rollback on the reply.
Is there a way to go? I tried to wrap the reply into a new transaction scope, but this did not work:
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
this.bus.Reply(message);
scope.Complete();
}
Any advice? Thanks in advance
Additional Information:
The orginal problem was that I did not throw (or rethrow) any exception but replying
to the originator in the catch section (I know its bad design).
The Saga is stored with a unique attribute applied on a id, which comes from the originating endpoint. And since I did not throw or pass any exception in the reply case (validation error occured), nservicebus always stored the saga. If the originating endpoint corrects the xml so that this is valid and resends a message (with the same id) nservicebus tries to store a new saga with the same id (causes concurrency exception on ravenDB because the saga with that unique property already exists). As a quick fix, I want to change the unique property and use instead the message id as the unique prop. In that case, I am sure that the message id is always unique and a saga concurrency exception could not happen again. Do you know if that causes any side effects?
You may be able to leverage the message handler pipeline. The first handler in your pipeline could do the validation and any response if necessary. During the validation, do not throw an exception, just reply. The second handler could initiate the Saga and set the state to be "Invalid" or something like that. My assumption is that you will get another request with valid data and then you will follow the "normal" process and set the state to "Valid" and continue on.

Accessing Context in an IMessageMutator implementer?

How can I access the current context from within a message mutator?
I also need to have access to the saga data.
I want to pass certain data transparently from both the sender and implementers (handlers). This data will be set in the outgoing headers. Depending on the situation, if the handler is of type Saga, I want to set some of these properties into the saga data.
Later when a call "ReplyToOriginator" is detected, I want to grab the values from saga and set it back into the headers of the reply message.
So how can I do this from within the message mutator?
All the examples I have seen so far seems to indicate that it has access only to the message and not context.

How do I set CurrentMessageContext.TimeSent for testing in NServiceBus?

I'm testing an NServiceBus saga that sends a command. The command has an attribute that tracks the time an action was performed. The handler for the message assigns CurrentMessageContext.TimeSent to LastSentOn in the outgoing message.
When I try to test the outgoing message, LastSentOn always has the value DateTime.MinValue, so....
How do I set CurrentMessageContext.TimeSent for testing in NServiceBus?
Josh - this is not a direct answer to your question, but have you seen this?
http://github.com/NServiceBus/NServiceBus/issues/808
Looks like CurrentMessageContext.TimeSent has been deprecated and is now just a setting in the message headers. Perhaps you can use the header value instead.

Where is the right place to add the user and time a command was issued in NServiceBus?

Some of my NServiceBus commands will need to track who issued the command and when. I'm very unsure as to the recommended way to implement this:
Should I create a base class MessageBase, add public Dictionary<string, string> Headers;, and implement IMutateOutgoingMessages?
Should it be added to the MessageContext? If so, how do I ensure the Bus adds it before every message (which needs the headers) is sent?
Is it already done and I just don't know how to access it? (It looks like the user is in the raw MSMQ message...)
NServiceBus already gives you the time the message was sent using the "NServiceBus.TimeSent" header.
Use the builtin NServiceBus headers dictionary and skip the MessageBase
Attaching user id is best done in a outgoing message mutator. Just grab the ID from eg the HttpContext and add it as a header.
http://support.nservicebus.com/customer/portal/articles/860492
To get the time (in your handler/saga):
Bus.CurrentMessageContext.TimeSent