Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Message.CreateMessage, what is the meaning of the "action" parameter?

Tags:

.net

wcf

Here's the deal:

public static Message CreateMessage(
    MessageVersion version,
    MessageFault fault,
    string action)

action: A description of how the message should be processed.

What do you guys put in there? "Handle with care!!!" or "FRAGILE"? Does it make any difference in the end?

like image 276
maxbeaudoin Avatar asked Aug 30 '10 18:08

maxbeaudoin


1 Answers

The "Action" is one of the strings in the message header.

For example, this call

        var m = Message.CreateMessage(MessageVersion.Default, "http://tempuri.org/MyMethod");

Produces this message

<s:Envelope
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
     <a:Action s:mustUnderstand="1">http://tempuri.org/MyMethod</a:Action>
 </s:Header>   <s:Body />
 </s:Envelope>

Each message has an "action" header, and each WCF operation has an "action" attribute. The WCF system will compare these values when determining which operation to dispatch each message to.

Normally, you aren't manually generating messages so you don't have to worry about this - it's all handled as expected by default values.

When you define the Service Contract you can explicitly associate an action string with an operation:

[ServiceContract]
interface MyService
{
   [OperationContract(Action="http://tempuri.org/MyMethod")]
   void ThisIsntReallyCalledMyMethod(string parameter1);
}
like image 139
Andrew Shepherd Avatar answered Nov 15 '22 01:11

Andrew Shepherd