In recent days, we have considered WebService encryption, and found that the action of soapmessage is unreliable.
Code
Public override void processmessage (soapmessage message)
{
Switch (message. stage)
{
Case soapmessagestage. beforeserialize: // The message. Action has a value.
Break;
Case soapmessagestage. afterserialize ://
Break;
Case soapmessagestage. beforedeserialize: // when the server retrieves message. Action, an exception is thrown, but the client can retrieve
Break;
Case soapmessagestage. afterdeserialize:
Break;
}
}
The process of searching has finally felt the benefits of WCF. Of course, the conversion is not feasible. The tracing code found that the request. headers has soapaction available.
Case soapmessagestage. beforedeserialize:
// This. actionname = message. Action; // The client can retrieve
String actionname = (string) httpcontext. Current. Request. headers ["soapaction"]. Trim ('"');
I hope the entire extension class can use action at any time, so I wrote the action in the two initialization methods.
Code
Public override object getinitializer (type T)
{
String strtype = T. tostring ();
If (strtype. lastindexof ("connectservice")> = 0)
This. isencrypt = false;
Else
This. isencrypt = true;
If (httpcontext. Current! = NULL)
This. actionname = (string) httpcontext. Current. Request. headers ["soapaction"]. Trim ('"');
Return this;
}
Public override void initialize (Object initializer)
{
Connectencryption connect = initializer as connectencryption;
If (connect! = NULL)
{
This. isencrypt = connect. isencrypt;
This.tar get = connect.tar get;
This. actionname = connect. actionname;
}
}
The first method [getinitializer (type T)] will only be executed once for each request, however, our soapextension extension class will be constructed multiple times (the trace code can be viewed at least twice), and the second method [initialize (Object initializer)] will be executed each time it is constructed. and use the object returned by the first method as the parameter [initializer] of the second method. The extension class of the above Code is connectencryption, inherited from soapextension.