Soap Extension to log

Source: Internet
Author: User
Tags soap
SoapExtension is not logging HTTP://FORUMS.ASP.NET/T/1165658.ASPX/1 ====================================

SOAP extension invocation sequence principle analysis

Recently I learned about WebService SOAP extension development, and when I learned that the biggest problem was the sequence of calls of different priority soapextension and the purpose of the ChainStream method, we knew SoapMessage had a stream property , then why can't we just manipulate the stream in SoapExtension's processmessage, for example your code might look like this:

Publicoverridevoidprocessmessage(soapmessagemessage)

        {

Switch (message. Stage)

            {

//serialization compresses this stream after

casesoapmessagestage.afterserialize:

message. Stream =compressstream(message. Stream);

break;

 

//To decompress this stream before deserialization

casesoapmessagestage.beforedeserialize:

message. Stream =decompressstream(message. Stream);

break;

default:

break;

            }

        }

///<summary>

///compress the input stream, returning the new stream after compression.

///</summary>

///<param name= "InputStream" > Input stream, the stream will be compressed </param>

///<returns> returns the new stream after compression. </returns>

privatestreamcompressstream(streaminputstream)

        {

//simulate code here

Returnnewmemorystream();

        }

///<summary>

///unzip the input stream and return the new stream after decompression.

///</summary>

///<param name= "Compressedstream" > Compressed input stream </param>

///<returns> returns the new stream after decompression. </returns>

privatestreamdecompressstream(streamcompressedstream)

        {

//simulate code here

Returnnewmemorystream();

        }

I very much hope that this code will execute correctly, but when WebService is called, the first Compressstream cannot be passed because it is empty. Read my explanation below and maybe you can find the answer.

before proceeding, please remember the following conclusions:

1. SOAP extensions are interceptors for their SOAP message processing during soapmessage (Soapclientmessage and SoapServerMessage types) transfers, It can intercept and insert code in four stages of the SoapMessage, four stages beforeserialize "AfterSerialize" BeforeDeserialize and Afterdeserialize.

2, throughout the WebService access process, ChainStream a total of four times, the client executes two times, on the server side to execute two times. The invocation of ChainStream is called sequentially, in order of the high priority of the SOAP extension to the low-priority call sequence.

3, each time the SoapMessage stage state changes, will call SoapExtension ProcessMessage. So this function executes 8 times altogether. It is important to note that SOAP extensions of different priorities are not called in the same order in different stages of the SOAP message transmission, and can be divided into two phases: the Serialize phase, which is executed from low to high with the priority of the SOAP extension. In the deserialize phase, its invocation is performed from high to low in accordance with the SOAP extension priority.

From the following code we can see the sequence of ProcessMessage calls:

Internalvoidrunextensions(soapextension[] extensions, BOOL throwonexception)

{

Extensions has been prioritized from high to the bottom.

if (extensions! = null)

{
Performed in BeforeDeserialize or afterdeserialize stages in order of precedence from highest to lowest

if (This.stage & (Soapmessagestage.afterdeserialize | soapmessagestage.beforedeserialize))! = ((soapmessagestage) 0))

{

for (inti = 0; i < extensions. Length; i++)

{

Extensions[i]. ProcessMessage (this);

if (this. Exception = null) && throwonexception)

{

Throw this. Exception;

}

}

}

Else

{

Performed in BeforeSerialize or afterserialize stages in order of priority from low to high

for (intJ = extensions. Length-1; J >= 0; j--)

{

EXTENSIONS[J]. ProcessMessage (this);

Related Article

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.