Discussion:
[Exodus-dev] using onBeforeMessage to trap/modify an outgoing message
John E. Arnold
2006-04-12 19:35:21 UTC
Permalink
Hi.

I am experimenting with the Exodus Plug-in API in C# (as mentioned in my
response to a post last week).

So far, I have been able to instrument the IExodusCharPlugin methods so I
can get a sense of the normal flow of messages. I have instrumented stubbed
implementations of all the methods but am asking for clarification with the
proper (and expected) use and behavior of the onBeforeMessage and
onAfterMessage methods.

onBeforeMessage question #1:

The documentation leads me to believe that I can modify the message by
modifying the contents of the string that is passed in as a reference. In
the pure COM interface, the body of the message is passed in as ( [in] BSTR
* Body ). In C#, importing the COM object turns this into a string reference
such as this: (ref string Body).

So, I tried a simple experiment in my implementation of onBeforeMessage:

public virtual void onBeforeMessage(ref string Body)
{
StringBuilder sb = new StringBuilder( "replacement body"
);

Body = sb.ToString();
}

Now I know that this may seem odd to people not used to C# since there's no
explicit pointer usage. However, I've written a similar test program in C#
to try to prove to myself that you can just assign the new string to the
'ref' parameter and it seems to work. Furthermore, when I put in some trace
calls inside my onBeforeMessage implementation, it does appear that the
value of 'Body' has been successfully changed to "replacement body".

However, when I look at the value of the string that shows up in the
subsequent call to onAfterMessage, the Body passed into onAfterMessage is
the original string passed into onBeforeMessage, not the modified value.

Can anyone explain what I'm missing in order to successfully change the
message as it passes through onBeforeMessage?


onBeforeMessage question #2:

This is probably related to finding a solution to the previous question...
The onBeforeMessage documentation indicates that I can prevent an outgoing
message from actually being sent by changing the Body parameter passed into
onBeforeMessage to an empty string.

Well, as you'd guess given my first question, I have also tried to set the
Body to the empty string ("") and the original message still passes through
and is sent out through Exodus to the intended recipient.

Any ideas about whether there's anything special about C#'s 'ref' handling
that would mess this up too?

Thanks for any insight that you might be able to provide for this.

- John -

Loading...