In Message.CreateMessage, what is the meaning of the "action" parameter?
Here's the deal:
public static Message CreateMessage(
MessageVersion version,
MessageFault fault,
string action)
action: A description of how 开发者_JS百科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?
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);
}
I asked a question about the SOAPAction recently: - I think that the SOAPAction header is used in routing messages within a WSDL operation, but I've not managed to find anything which explicitly states that the @soapAction attrib has to be unique within the containing operation (which would seem to be a prerequisite for a sane WSDL routing component....)
精彩评论