Exploration of taking the current action in soapextension

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.