Sei sulla pagina 1di 10

: g ni w oll of e h t e r a e ci v r e s b e W L M X n a h ti w n u r ti e v a h d n a n oi s n e t x e P A O S a dli u b o t s p e t s ci s a b e h T . n oi s n e t x e P A O S a dli u b o t w o h t a k o o l s' t el , y til a n oi t c n u f s ti m r o f r e p n a c ti n e h w d n a , o d n a c n oi s n e t x e P A O S a t a h w w o n k u o y t a h t w o N . r e v r e s d n a t n eil c e h t h t o b n o n u r o t d e e n t o n s e o d n oi s n e t x e P A O S e h t , el bi s s o p mi n o i t a zil a i r e s e d s e k a m t a h t y a w a ni P A O S e h t y fi d o m t o n s e o d n oi s n e t x e P A O S e h t a fi , o sl A . e g a s s e m P A O S e h t e zil ai r e s e d n a c e r u t c u r t s a r f ni T E N . P S A e h t d n a g ni n n u r t o n e r e w n o i s n e t x e P A O S a fi e v a h d l u o w ti e g a s s e m P A O S e m a s e h t s e v i e c e r t n e i pi c e r e h t , e s a c s i h t n I . r e v r e s r o t n e il c e h t y l n o n o n u r n a c , s e g a s s e m P A O S e h t s g ol yl p mi s t a h t n oi s n e t x e P A O S a s a h c u s , e g a s s e m P A O S e h t y fi d o m t o n s e o d t a h t n oi s n e t x e P A O S a , e s r u o c f O . t c ej b o n a o t ni e g a s s e m P A O S e h t e zil ai r e s e d t o n n a c e r u t c u r t s a r f ni T E N . P S A e h t n e h t , d e t p y r c e d t o n si e g a s s e m P A O S e h t f I . r e v r e s e h t n o e g a s s e m P A O S e h t t p y r c e d t s u m n oi s n e t x e P A O S g ni d n o p s e r r o c a , e g a s s e m P A O S e h t t p y r c n e d n a t n ei l c e h t n o n u r o t e r e w n oi s n e t x e P A O S a fi , si t a h T . r e v r e s e h t d n a t n eil c e h t h t o b n o e n o d e b t s u m s n oi t a ci fi d o m e h t , e g a s s e m P A O S a f o s t n e t n o c e h t s eif i d o m n oi s n e t x e P A O S a n e h w , yl l a ci p y T .

e g a t s e zil ai r e s e D e r o f e B e h t ni g ni t p y r c e d d n a egats ezilaireSretfA eht ni gnitpyrcne si noisnetxe PAOS eht ,esac siht nI .noitaremune ] xpsa.)17.SV( e g a t s e g a s s e m p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ e g a t S e g a s s e M p a o S e h t ni d e ni f e d e r a , e g a s s e m P A O S e h t y fi d o m r o t c e p s ni t h gi m n oi s n e t x e P A O S a e r e h w , s e s a h p e s e h T . e g a s s e m P A O S e h t s e zil ai r e s e d T E N . P S A e r of e b r e v r e s b e W e h t n o e g a s s e m P A O S e h t t p y r c e d n e h t d n a , s t n e m u g r a s' t n ei l c e h t s e zil ai r e s T E N . P S A r e tf a e g a s s e m P A O S e h t f o n oi t r o p L M X e h t t p y r c n e t h gi m n o i s n e t x e P A O S n oi t p y r c n e n a , e c n a t s ni r o F . s e s a h p e zil ai r e s e d d n a e zi l ai r e s e s e h t f o h c a e r e tf a d n a e r of e b s e g a s s e m P A O S e h t y fi d o m r o t c e p s ni o t e r u t c u r t s a r f ni e h t o t ni d e t c ej ni e b n a c n oi s n e t x e P A O S A . r e t u p m o c t n ei l c e ci v r e s b e W L M X e h t d n a r e t u p m o c e ci v r e s b e W L M X e h t h t o b n o s e s a h p g ni r u d L M X s e zi l ai r e s e d d n a s e zi l ai r e s T E N . P S A , e e s n a c u o y s A

. e ci v r e s b e W L M X n a o t t n eil c a m o r f ll a c a f o s e s a h p r oj a m e h t s e nil t u o ci h p a r g g ni w oll of e h t , r e v e w o H . ] x p s a . ) 1 7 . S V ( z w 0 0 s 5 0 x / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e mi t ef i L e ci v r e S b e W L M X n a f o y m o t a n A e e s , e c i v r e s b e W L M X n a f o e mi t e fil e h t f o w e i v r e v o n a r o F . e ci v r e s b e W L M X n a f o e mi t efi l e h t d n a t s r e d n u t s rif o t l u f e s u s i ti , s k r o w n oi s n e t x e P A O S a w o h d n a t s r e d n u o T . e ci v r e s b e W L M X g ni t si x e n a h ti w n u r o t m h ti r o gl a n o i s s e r p m o c r o n oi t p y r c n e n a t n e m el p mi n a c u o y , e c n a t s ni r o F . t n eil c e ci v r e s b e W L M X n a r o e ci v r e s b e W L M X n a m o r f d n a o t t n e s s e g a s s e m P A O S e h t g ni r e tl a y b e ci v r e s b e W L M X n a f o y ti l a n o i t c n u f e h t t n e m g u a o t s r e p o l e v e d w o ll a s n oi s n e t x e P A O S

. d e v r e s e r s t h g i r ll A . n oi t a r o p r o C t f o s o r ci M 9 0 0 2

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx

Altering the SOAP Message Using SOAP Extensions

Altering the SOAP Message Using SOAP Extensions

Page 1 of 10

30-04-2009

- n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ n oi s n e t x E p a o S m o rf s s al c a e vi r e D

e mi t e fil e ci v r e s b e W L M X n a f o y m o t a n A

e di u G s' r e p ol e v e D k r o w e m a r F T E N .

e do C y po C

. d o h t e m m a e r t S ni a h C e h t f o n oi t a t n e m el p mi n o m m o c a s e t a r t s n o m e d el p m a x e g n i w o ll o f e h T . d o h t e m m a e r t S ni a h C e h t n i h ti w s e c n e r ef e r m a e r t S h t o b e v a s o t t n a t r o p mi si ti , e r o f e r e h T . m a e r t S ni a h C r o f e ul a v n r u t e r m a e r t S e h t o t e ti r w d n a m a e r t S ni a h C o t ni d e s s a p m a e r t S e h t m o r f d a e r dl u o h s n oi s n e t x e P A O S a , e g a s s e m P A O S e h t s ei fi d o m d n a e g a t S e g a s s e M p a o S h c a e g ni r u d s e t u c e x e n oi s n e t x e P A O S e h t s A . d o h t e m m a e r t S ni a h C e h t ni h ti w ti n r u t e r d n a , e l b ai r a v r e b m e m e t a vi r p a ni t a h t e v a s , m a e r t S a f o e c n a t s n i w e n a e t a e r c dl u o h s n oi s n e t x e P A O S A . y fi d o m d l u o h s n o i s n e t x e P A O S a m a e r t S e h t t o n si , r e v e w o h , m a e r t S ni a h C o t ni d e s s a p m a e r t S e h T . e g a s s e m P A O S e h t s e ifi d o m r o s t c e p s n i n oi s n e t x e P A O S a n e h w , e g a t S e g a s s e M p a o S e h t g n i r u d s s e c c a r e t a l r of el b a i r a v r e b m e m a n i e c n e r ef e r si h t e v a s dl u o h s n oi s n e t x e P A O S a , e r o f e r e h T . e g a s s e m P A O S e h t o t s e g n a h c ri e h t e d a m d n a d e t u c e x e e v a h ) s ei ti r o i r p n oi s n e t x e P A O S t u o b a sli a t e d r o f s d o h t e M e ci v r e S b e W L M X h ti w n u R o t n oi s n e t x E P A O S e h t e r u gi f n o C e e s ( y ti r o i r p r e w ol f o s n oi s n e t x e P A O S r e t f a e g a s s e m P A O S e h t f o L M X e h t o t s r ef e r m a e r t S si h T . ] x p s a . ) 1 7 . S V ( e g a t s e g a s s e m p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e g a t S e g a s s e M p a o S y n a o t r oi r p , e c n o m a e r t S ni a h C e h t o t ni d e s s a p si ] x p s a . ) 1 7 . S V ( m a e r t s . oi . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ m a e r t S a o t e c n e r e f e r A . s e g a s s e m P A O S e r u t uf f o s t n e t n o c e h t n i a t b o o t d e s u e b n a c t a h t m a e r t s e h t o t e c n e r e f e r a e vi e c e r o t y ti n u t r o p p o y l n o e h t si t a h t s a , d o h t e m ] x p s a . ) 1 7 . S V ( m a e r t s ni a h c . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ m a e r t S ni a h C e h t e di r r e v o t s u m u o y , e g a s s e m P A O S a y fi d o m o T

. n oi t p y r c e d g ni d n o p s e r r o c d n a n oi t p y r c n e e h t s m r of r e p s s al c ] x p s a . ) 1 7 . S V ( n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ n oi s n e t x E p a o S e h t m o rf g ni v i r e d s s al c e h t n e h t , n oi s n e t x e P A O S n o i t p y r c n e n a si n oi s n e t x e P A O S e h t fi , si t a h T . n oi s n e t x e P A O S e h t f o y til a n oi t c n uf e h t s m r o f r e p t a h t s s al c e h t si ] x p s a . ) 1 7 . S V ( n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ n oi s n e t x E p a o S m o r f g ni vi r e d s s al c e h T

. s d o h t e m e ci v r e s b e W L M X ci fi c e p s h ti w n u r o t n oi s n e t x e P A O S e h t e r u gi f n o C . s e g a t s r o e g a t S e g a s s e M p a o S t n e ni t r e p e h t g n i r u d s e g a s s e m P A O S e h t s s e c o r P . a t a d ci fi c e p s n oi s n e t x e P A O S e z il ai ti n I . s e g a s s e m P A O S e r u t uf g ni t n e s e r p e r m a e r t S e h t o t e c n e r e f e r a e v a S . ] x p s a . ) 1 7 . S V ( n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx

] c i s a B l a u si V [

Altering the SOAP Message Using SOAP Extensions

Derive a Class from SoapExtension

Save a Reference to the Stream Representing Future SOAP Messages

[C#]

// Save the Stream representing the SOAP request or SOAP response into // a local memory buffer. public override Stream ChainStream( Stream stream ){ // Save the passed in Stream in a member variable. oldStream = stream;

' Create a new instance of a Stream and save that in a member ' variable. newStream = New MemoryStream() Return newStream End Function

' Save the Stream representing the SOAP request or SOAP response ' into a local memory buffer. Public Overrides Function ChainStream(stream As Stream) As Stream ' Save the passed in Stream in a member variable. oldStream = stream

// Create a new instance of a Stream and save that in a member // variable. newStream = new MemoryStream(); return newStream;

Page 2 of 10

30-04-2009

e do C y po C

. e ci v r e s b e W L M X e h t f o e p y t e h t n o d e s a b , d e t u p m o c s i e m a n eli f d e h c a c e h t , eli f n oi t a r u g if n o c a g ni s u d e r u gi f n o c si n oi s n e t x e P A O S e h t f I . d e h c a c si e t u bi r t t a e h t ni d ei fi c e p s e m a n e lif e h t , a e s a c si h t ni , e t u bi r t t a n a g ni s u d e r u g if n o c s i n oi s n e t x e P A O S e h t f I . d e r u gi f n o c yll a u t n e v e si n oi s n e t x e P A O S e h t w o h n o d e s a b , yl t n e r e f fi d d o h t e m r e zil ai ti n I t e G e h t ni a t a d f o e c ei p d e h c a c e h t s e zil a i ti ni el p m a x e e d o c g n i w o ll o f e h T . r e zil ai ti n I t e G o t d e s s a p si e ci v r e s b e W L M X e h t g ni t n e m el p mi s s al c e h t f o e p y T e h t t s uj , eli f n oi t a r u gif n o c a g ni s u d e r u g if n o c s i n oi s n e t x e P A O S e h t f I . s e p y t a t a d ri e h t d n a s r e t e m a r a p f o r e b m u n e h t s a h c u s , d o h t e m e ci v r e s b e W L M X e h t t u o b a s li a t e d e p y t o t o r p s e di v o r p o f n I d o h t e Ml a ci g o L e h T . e r u t c u r t s a r f ni T E N . P S A e h t y b r e zil ai ti n I t e G o t ni d e s s a p e r a ] x p s a . ) 1 7 . S V ( o f ni d o h t e ml a c i g ol . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ of n I d o h t e Ml a ci g o L a d n a , ti h ti w d e t ai c o s s a s ei t r e p o r p m o t s u c y n a g ni d u l c ni , e t u bi r t t a e h t , e t u b i r t t a n a g ni s u d e r u gif n o c si n oi s n e t x e P A O S e h t f I . d e r u gi f n o c si n oi s n e t x e P A O S e h t w o h n o p u s d n e p e d d o h t e m r e zil ai ti n I t e G e h t n i n oi s n e t x e P A O S a o t e l b al i a v a n o i t a m r of ni e h T .dohtem ezilaitinI e h t ni d o h t e m e c i v r e s b e W L M X r o e c i v r e s b e W L M X t a h t h ti w s n u r n o i s n e t x e P A O S e h t e mi t h c a e a t a d d e h c a c e h t d e s s a p e r a s n oi s n e t x e P A O S . s n oi s n e t x e P A O S e h t y b e s u e r u t u f r of e r u t c u r t s a rf ni T E N . P S A e h t y b d e h c a c si n oi s n e t x e P A O S a y b r e zil ai ti n I t e G m o r f d e n r u t e r a t a d e h T . d e s s e c c a si e ci v r e s b e W L M X n a e m i t t s ri f e h t yl n o e r u t c u r t s a r f ni T E N . P S A e h t y b d ell a c si r e zil ai ti n I t e G , eli f n oi t a r u g if n o c a ni d e r u gi f n o c si n oi s n e t x e P A O S e h t f I . si s a b d o h t e m e ci v r e s b e W L M X - r e p a n o e r u t c u r t s a r f ni T E N . P S A e h t y b d ell a c si r e zil ai ti n I t e G , e t u bi r t t a n a g ni s u d e r u gi f n o c si n oi s n e t x e P A O S e h t f I . ) s d o h t e M e ci v r e S b e W L M X h ti w n u R o t n oi s n e t x E P A O S e h t e r u gi f n o C e e s ( d e r u gif n o c si n oi s n e t x e P A O S e h t w o h n o g ni d n e p e d , h ti w n u r o t d e r u gi f n o c si n o i s n e t x e P A O S e h t t a h t d e s s e c c a si d o h t e m e ci v r e s b e W L M X r o e ci v r e s b e W L M X n a e mi t t s ri f e h t yl n o d ell a c si r e zil ai ti n I t e G . ] x p s a . ) 1 7 . S V ( e zil a i ti ni . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ e z il ai ti n I d n a ] x p s a . ) 1 7 . S V ( r e zi l ai t i ni t e g . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ r e zil ai ti n I t e G : a t a d g n i z il ai ti ni r o f s d o h t e m o w t s a h ] x p s a . ) 1 7 . S V ( n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ n oi s n e t x E p a o S m o r f g ni vi r e d s s al c e h T . ) h ti w g ni n n u r si n oi s n e t x e P A O S e h t d o h t e m e ci v r e s b e W L M X e h t r o e ci v r e s b e W L M X e h t f o e m a n e h t n o d e s a b ( n oi t a m r o f ni g n i g g o l e h t e v a s o t eli f a f o e m a n e h t e zil a i ti ni t h gi m d o h t e m e c i v r e s b e W L M X n a m o rf d n a o t t n e s e g a s s e m P A O S e h t s g ol t a h t n oi s n e t x e P A O S a , e c n a t s ni r o F . o t d eil p p a si ti d o h t e m e ci v r e s b e W L M X r o e ci v r e s b e W L M X e h t n o d e s a b , a t a d l a n r e t n i e zil ai ti ni n a c n oi s n e t x e P A O S A
TraceExtensionAttribute

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx Altering the SOAP Message Using SOAP Extensions

Initialize SOAP Extension Specific Data

Public Overloads Overrides Function GetInitializer(WebServiceType As _ Type) As Object ' Return a file name to log the trace information, based on the type. Return "C:\" + WebServiceType.FullName + ".log" End Function [C#] // When the SOAP extension is accessed for the first time, the XML // Web service method it is applied to is accessed to store the file // name passed in, using the corresponding SoapExtensionAttribute. public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) { return ((TraceExtensionAttribute) attribute).Filename; } // The extension was configured to run using a configuration file instead of

] c i s a B l a u si V [

' ' ' '

' When the SOAP extension is accessed for the first time, the XML ' Web service method it is applied to is accessed to store the file ' name passed in, using the corresponding SoapExtensionAttribute. Public Overloads Overrides Function GetInitializer(methodInfo As _ LogicalMethodInfo, attribute As SoapExtensionAttribute) As Object Return CType(attribute, TraceExtensionAttribute).Filename End Function

The extension was configured to run using a configuration file instead of an attribute applied to a specific XML Web service method. Return a file name, based on the class implementing the XML Web service's type.

Page 3 of 10

30-04-2009

e do C y po C

. eli f a o t n e t ti r w si L M X e h t , L M X o t ni d e zil ai r e s n e e b e v a h s r e t e m a r a p e h t e r e h w e n o si e g a t S e g a s s e M p a o S e h t fi , e c a r t e h t g ni r u D . e ci v r e s b e W L M X n a o t ll a c a s e c a r t t a h t n o i s n e t x e P A O S a f o d o h t e m e g a t S s s e c o r P e h t si el p m a x e e d o c g n i w o ll o f e h T . ni d e s s a p si ] x p s a . ) 1 7 . S V ( e g a s s e m t n eil c p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ e g a s s e M t n ei l C p a o S a n e h t , t n e il c e ci v r e s b e W L M X n a h ti w g ni n n u r si n oi s n e t x e P A O S e h t f I . ni d e s s a p si ] x p s a . ) 1 7 . S V ( e g a s s e m r e v r e s p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e g a s s e M r e v r e S p a o S a n e h t , e ci v r e s b e W L M X n a h ti w g ni n n u r si n oi s n e t x e P A O S e h t f I . e g a t s r al u ci t r a p t a h t t a e g a s s e m P A O S e h t t u o b a n oi t a m r o f ni h t i w ni d e s s a p si , t i m o rf g ni v i r e d s s al c a r o , ] x p s a . ) 1 7 . S V ( e g a s s e m p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e g a s s e M p a o S a , d ell a c s i d o h t e m ] x p s a . ) 1 7 . S V ( e g a s s e m s s e c o r p . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ e g a s s e M s s e c o r P . n oi s n e t x E p a o S e mi t h c a E . n oi t a r e m u n e ] x p s a . ) 1 7 . S V ( e g a t s e g a s s e m p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ e g a t S e g a s s e M p a o S e h t ni d e nif e d s e g a t s e h t f o h c a e t a T E N . P S A y b s e m i t l a r e v e s d ell a c si d o h t e m si h T . d o h t e m ] x p s a . ) 1 7 . S V ( e g a s s e m s s e c o r p . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e g a s s e M s s e c o r P . n oi s n e t x E p a o S e h t si n o i t a t n e m e l p mi f o e c ei p e r o c e h t , ] x p s a . ) 1 7 . S V ( n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ n oi s n e t x E p a o S m o r f d e v i r e d s s a l c e h t n I

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx Altering the SOAP Message Using SOAP Extensions

Order SOAP Extensions Methods are

Process the SOAP Messages

// an attribute applied to a specific XML Web service method. public override object GetInitializer(Type WebServiceType) { // Return a file name to log the trace information, based on the type. return "C:\\" + WebServiceType.FullName + ".log";}

public override void ProcessMessage(SoapMessage message) { switch (message.Stage) { case SoapMessageStage.BeforeSerialize: break; case SoapMessageStage.AfterSerialize: // Write the SOAP message out to a file. WriteOutput( message ); break; case SoapMessageStage.BeforeDeserialize: // Write the SOAP message out to a file. WriteInput( message ); break; case SoapMessageStage.AfterDeserialize: break; default: throw new Exception("invalid stage"); } } [Visual Basic] Public Overrides Sub ProcessMessage(message As SoapMessage) Select Case message.Stage Case SoapMessageStage.BeforeSerialize Case SoapMessageStage.AfterSerialize ' Write the SOAP message out to a file. WriteOutput(message) Case SoapMessageStage.BeforeDeserialize ' Write the SOAP messae out to a file. WriteInput(message) Case SoapMessageStage.AfterDeserialize Case Else Throw New Exception("invalid stage") End Select End Sub

Page 4 of 10

30-04-2009

] # C[

. s r e t e m a r a p t u o y n a d n a e ul a v n r u t e r e h t s e vi e c e r t n eil c e h T . s s al c y x o r p e h t f o e c n a t s ni e h t o t s r e t e m a r a p t u o y n a d n a e ul a v n r u t e r e h t s e s s a p T E N . P S A .ezilaireseDretfA o t t e s e g a t S e g a s s e M p a o S e h t h ti w d e k o v ni s i d o h t e m e g a s s e M s s e c o r P e h T . s r e t e m a r a p t u o y n a d n a e ul a v n r u t e r e h t o t ni L M X e h t s e zil a i r e s e d T E N . P S A . e zil ai r e s e D e r o f e B o t t e s e g a t S e g a s s e M p a o S e h t h ti w d e k o v ni s i d o h t e m e g a s s e M s s e c o r P e h T . e g a s s e m P A O S e h t s e vi e c e r r e t u p m o c t n e il c e h t n o T E N . P S A

. t n eil c e ci v r e s b e W L M X e h t o t k c a b k r o w t e n e h t r e v o e g a s s e m e s n o p s e r P A O S e h t s d n e s T E N . P S A .ezilaireSretfA ot tes egatSegasseMpaoS eht htiw dekovni si dohtem egasseMssecorP ehT . L M X o t ni s r e t e m a r a p t u o d n a e u l a v n r u t e r e h t s e zil a i r e s r e v r e s b e W e h t n o T E N . P S A . e zil ai r e S e r o f e B o t t e s e g a t S e g a s s e M p a o S e h t h ti w d e k o v ni s i d o h t e m e g a s s e M s s e c o r P e h T . s r et e m a r a p t u o y n a d n a e ul a v n r u t e r e h t g ni t t e s yl l a u t n e v e , e d o c s t i s e t u c e x e d o h t e m e ci v r e s b e W L M X e h T .r e vr e s b e W e h t s a r e t u p m o c e m as e h t n o s e di s e r t c ej b o si h T . s t n e m u g r a d e zi l ai r e s e d e h t ni g ni s s a p , d o h t e m e ci v r e s b e W L M X e h t s e k o v n i d n a e ci v r e s b e W L M X e h t g ni t n e m el p mi s s al c e h t f o e c n a t s ni w e n a s e t a e r c T E N . P S A .ezilaireseDretfA o t t e s e g a t S e g a s s e M p a o S e h t h ti w d e k o v ni s i d o h t e m e g a s s e M s s e c o r P e h T . L M X e h t ni h ti w s t n e m u g r a e h t s e zil a i r e s e d T E N . P S A . e zil ai r e s e D e r o f e B o t t e s e g a t S e g a s s e M p a o S e h t h ti w d e k o v ni s i d o h t e m e g a s s e M s s e c o r P e h T . d e k o v ni s i d o h t e m m a e r t S ni a h C e h T .dekovni si dohtem ezilaitinI ehT . r e v r e s e ht n o g ni n n u r n oi s n e t x e P A O S e h t n o d e k o v ni si d o h t e m r e zil ai ti n I t e G e h t , e d i s r e v r e s e h t n o e ci v r e s b e W L M X si h t h ti w d e t u c e x e s a h n oi s n e t x e P A O S si h t e mi t t s r if e h t s i si h t fi , r e v r e s b e W e h t n O . r e v r e s b e W e h t n o d e t a e r c s i n oi s n e t x e P A O S e h t f o e c n a t s ni w e n A . e g a s s e m P A O S e h t s e vi e c e r r e v r e s b e W e h t n o T E N . P S A

. e ci v r e s b e W L M X e h t g ni t s o h r e v r e s b e W e h t o t k r o w t e n e h t r e v o e g a s s e m P A O S e h t s d n e s r e t u p m o c t n e il c e h t n o T E N . P S A .ezilaireSretfA ot tes egatSegasseMpaoS eht htiw dekovni si dohtem egasseMssecorP ehT . L MX o t ni d o h t e m e ci v r e s b e W L M X e h t f o s t n e m u g r a e h t s e zil a i r e s r e t u p m o c t n e il c e h t n o T E N . P S A . e zil ai r e S e r o f e B o t t e s ] x p s a . ) 1 7 . S V ( e g a t s e g a s s e m p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e g a t S e g a s s e M p a o S e h t h ti w d e k o v ni si d o h t e m ] x p s a . ) 1 7 . S V ( e g a s s e m s s e c o r p . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e g a s s e M s s e c o r P e h T . d e k o v ni s i d o h t e m ] x p s a . ) 1 7 . S V ( m a e r t s ni a h c . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ m a e r t S ni a h C e h T . d e k o v ni s i d o h t e m ] x p s a . ) 1 7 . S V ( e zil a i ti ni . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e z il ai ti n I e h T . t n e il c e h t n o g ni n n u r n oi s n e t x e P A O S e h t n o d e k o v ni s i d o h t e m ] x p s a . ) 1 7 . S V ( r e zi l ai t i ni t e g . n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ r e zil ai ti n I t e G e h t n e h t , t n eil c e h t n o e ci v r e s b e W L M X si h t h ti w d e t u c e x e s a h n oi s n e t x e P A O S si h t e mi t t s rif e h t si si h t f I . t n e il c e h t n o d e t a e r c s i n oi s n e t x e P A O S e h t f o e c n a t s ni w e n A . s s al c y x o r p e h t n o d o h t e m a s e k o v ni t n ei l c A

. T E N . P S A y b d e r o n gi e r a h c a e n o g ni n n u r n oi s n e t x e P A O S e h t h ti w d e t ai c o s s a s p e t s e h t , r e v r e s e h t d n a t n e il c e h t h t o b n o g ni n n u r t o n si n oi s n e t x e P A O S e h t f I . r e v r e s d n a t n eil c e h t h t o b n o g ni n n u r si n oi s n e t x e P A O S e h t t a h t e m u s s a s p e t s g ni w oll of e h T . d o h t e m e ci v r e s b e W L M X n a f o n oi t a c o v n i e h t t u o h g u o r h t s d o h t e m n oi s n e t x e P A O S s e k o v ni T E N . P S A n e h w t a k o ol s' t e l , e di r r e v o t s u m n oi s ne t x e P A O S a s d o h t e m e h t t a d e k o ol e v a h u o y t a h t w o N

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx

Altering the SOAP Message Using SOAP Extensions

Invoked

Page 5 of 10

30-04-2009

.6 .5 .4 .3 .2 .1

e di s t n eil C
.41 .31 .21 .11 .01 .9 .8 .7 .6 .5 .4 .3 .2 .1

e di s r e v r e S
.9 .8 .7

.6 .5 .4 .3 .2 .1

e di s t n eil C

e do C y po C
. f o y ti r oi r p a s a h d n a p u o r g y ti r o i r p e vi t al e r e h t ni h t i w s n u r n oi s n e t x e P A O S e h t t a h t s ei fi c e p s t a h t eli f n oi t a r u gi f n o c a si el p m a x e e d o c g n i w o ll o f e h T . y ti r oi r p e vi t al e r t s e w ol e h t e v a h 1 f o g ni t t e s p u o r g a h ti w e s o h T . y ti r oi r p e v i t al e r t s e h gi h e h t e v a h 0 f o g n i t t e s p u o r g a h ti w eli f n oi t a r u gif n o c a g ni s u d e r u g if n o c s n oi s n e t x e P A O S . p u o r g m ui d e m e h t f o s r e b m e m e r a e t u bi r t t a n a g ni s u d e r u g if n o c s n oi s n e t x e P A O S . 1 r o 0 f o g n i t t e s p u o r g a h ti w eli f n o i t a r u gi f n o c e h t ni d ei fi c e p s s n oi s n e t x e P A O S d n a e t u bi r t t a n a g ni s u d e r u gi f n o c s n oi s n e t x e P A O S : e r a s n oi s n e t x e P A O S r o f s p u o r g y ti r oi r p e vi t a l e r e e r h t e h T . )t s e h g i h e h t g n i e b 0( y ti r oi r p e vi t al e r e h t r e h gi h e h t , si y t r e p o r p y ti r oi r p e h t r e w ol e h T . r e b m e m h c a e s e h s i u g ni t si d y t r e p o r p y ti r oi r p e h t , p u o r g h c a e ni h ti W . s p u o r g y ti r oi r p e e r h t f o e n o ni e r a s n oi s n e t x e P A O S . k r o w t e n e h t r e v o d e vi e c e r r o t n e s g ni e b e g a s s e m P A O S e h t o t s e t u c e x e ti r e s ol c e h t , si n oi s n e t x e P A O S a y ti r oi r p e h t r e h gi h e h T . d o h t e m e ci v r e s b e W L M X n a h t i w n u r o t d e r u gi f n o c e r a s n oi s n e t x e P A O S e l pi tl u m n e h w n oi t u c e x e f o r e d r o e v i t al e r e h t s e t a t ci d t a h t m e h t o t d e n gi s s a y ti r o i r p a e v a h s n oi s n e t x e P A O S
Logger.LoggerExtension 0 1

.ytiroirp no elbat siht gniwollof sliated eht e e S . f o r e b m e m a si n oi s n e t x e P A O S a p u o r g e h T . p u o r g s ti n i h ti w n oi s n e t x e P A O S e h t f o y ti r o i r p e v i t a l e r e h T . ni s e di s e r t i y l b m e s s a e h t d n a n oi s n e t x e P A O S e h t f o e p y t e h T

noitpircseD

. s e i t r e p o r p g ni w oll of e h t s a h t n e m el e L M X d d a e h T . eli f n oi t a r u gif n o c e h t f o e p o c s e h t ni h ti w e ci v r e s b e W L M X y r e v e h ti w n u r o t t n a w u o y n oi s n e t x e P A O S h c a e r o f s t n e m el e L M X d d a , t n e m el e L M X s e p y T n oi s n e t x E p a o s e h t n i h t i W . elif n oi t a r u gi f n o c e h t f o n oi t c e s s e ci v r e S b e w e h t o t d e d d a e b t s u m t n e m el e L M X s e p y T n oi s n e t x E p a o s a , yl l a ci fi c e p S . e lif gif n o c . b e W r o gi f n o c . p p A e t ai r p o r p p a e h t r e h ti e o t s ei r t n e d d a , el if n oi t a r u gi f n o c a f o e p o c s e h t ni h ti w s e ci v r e s b e W L M X ll a h t i w s n u r n oi s n e t x e P A O S a t a h t y fi c e p s o T . yl t r o h s d e s s u c si d si h ci h w , n oi s n e t x e P A O S e h t f o y ti r oi r p e vi t al e r e h t s t n e s e r p e r y t r e p o r p y ti r oi r P e h T . y t r e p o r p e p y T n oi s n e t x E e h t ni n oi s n e t x e P A O S e h t f o e p y t e h t n r u t e r dl u o h s n oi s n e t x e P A O S A . y ti r oi r P d n a e p y T n oi s n e t x E : s ei t r e p o r p o w t s a h e t u bi r t t A n oi s n e t x E p a o S . ] x p s a . ) 1 7 . S V ( e t u bi r t t a n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e t u bi r t t A n oi s n e t x E p a o S m o rf s s al c a e vi r e d , e t u b i r t t a m o t s u c a e s u o T . ] x p s a . ) 1 7 . S V ( a 3 k y 1 a z k / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ s n oi t a ci l p p A g ni r u gi f n o C e e s , k r o w s eli f n oi t a r u gif n o c w o h n o sli a t e d r o F . eli f n oi t a r u gi f n o c e h t f o e p o c s e h t ni h ti w s e ci v r e s b e W

L M X ll a h ti w s n u r n oi s n e t x e P A O S e h t , d e s u si eli f n oi t a r u gi f n o c a n e h W . h ti w n u r o t n oi s n e t x e P A O S e h t t n a w u o y d o h t e m e ci v r e s b e W L M X h c a e o t ti y l p p a , e t u bi r t t a m o t s u c a e s u o T . eli f n oi t a r u gi f n o c a g n i y fi d o m y b n u r o t d e r u gi f n o c r o e t u bi r t t a m o t s u c a g ni s u n u r o t d e r u gif n o c e b n a c n oi s n e t x e P A O S A

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx Altering the SOAP Message Using SOAP Extensions


<configuration> <system.web> <webServices> <soapExtensionTypes> <add type="Logger.LoggerExtension,logger" priority="1" group="0" /> </soapExtensionTypes> </webServices> </system.web>
p u or g y ti r oi r p e p yt

Configure the SOAP Extension to Run with XML Web Service Methods

Page 6 of 10

30-04-2009

y t re p o rP

Altering the SOAP Message Using SOAP Extensions

Page 7 of 10

</configuration>

Imports Imports Imports Imports

System System.Web.Services System.Web.Services.Protocols System.IO

' Define a SOAP Extension that traces the SOAP request and SOAP response ' for the XML Web service method the SOAP extension is applied to. Public Class TraceExtension Inherits SoapExtension Private oldStream As Stream Private newStream As Stream Private m_filename As String ' Save the Stream representing the SOAP request or SOAP response into ' a local memory buffer. Public Overrides Function ChainStream(stream As Stream) As Stream oldStream = stream newStream = New MemoryStream() Return newStream End Function ' When the SOAP extension is accessed for the first time, the XML Web ' service method it is applied to is accessed to store the file ' name passed in, using the corresponding SoapExtensionAttribute. Public Overloads Overrides Function GetInitializer(methodInfo As _ LogicalMethodInfo, _ attribute As SoapExtensionAttribute) As Object Return CType(attribute, TraceExtensionAttribute).Filename End Function ' The SOAP extension was configured to run using a configuration file ' instead of an attribute applied to a specific XML Web service ' method. Return a file name based on the class implementing the Web ' Service's type. Public Overloads Overrides Function GetInitializer(WebServiceType As _ Type) As Object ' Return a file name to log the trace information to, based on the ' type. Return "C:\" + WebServiceType.FullName + ".log" End Function ' Receive the file name stored by GetInitializer and store it in a ' member variable for this specific instance. Public Overrides Sub Initialize(initializer As Object) m_filename= CStr(initializer) End Sub ' If the SoapMessageStage is such that the SoapRequest or SoapResponse ' is still in the SOAP format to be sent or received over the network, ' save it out to file. Public Overrides Sub ProcessMessage(message As SoapMessage) Select Case message.Stage Case SoapMessageStage.BeforeSerialize Case SoapMessageStage.AfterSerialize WriteOutput(message) Case SoapMessageStage.BeforeDeserialize WriteInput(message) Case SoapMessageStage.AfterDeserialize Case Else Throw New Exception("invalid stage") End Select End Sub ' Write the SOAP message out to a file. Public Sub WriteOutput(message As SoapMessage) newStream.Position = 0

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx

e do C y po C
30-04-2009

. n e t ti r w si elif g ol e h t h ci h w n i y r o t c e ri d e h t o t e ti r w o t n o i s si m r e p e v a h t s u m t n u o c c a r e s u T E N P S A e h t , e ci v r e s b e W L M X n a h t i w n u r o t d e ll a t s ni s i n oi s n e t x e P A O S g n i w ol l o f e h t f I . t n ei l c e ci v r e s b e W L M X r o e ci v r e s b e W L M X n a m o r f d n a o t t n e s s e g a s s e m P A O S e h t s g o l t a h t n oi s n e t x e P A O S a si el p m a x e e d o c g n i w o ll o f e h T ] c i s a B l a u si V [

Altering the SOAP Message Using SOAP Extensions

Page 8 of 10

Dim fs As New FileStream(m_filename, FileMode.Append, _ FileAccess.Write) Dim w As New StreamWriter(fs) w.WriteLine("-----Response at " + DateTime.Now.ToString()) w.Flush() Copy(newStream, fs) w.Close() newStream.Position = 0 Copy(newStream, oldStream) End Sub ' Write the SOAP message out to a file. Public Sub WriteInput(message As SoapMessage) Copy(oldStream, newStream) Dim fs As New FileStream(m_filename, FileMode.Append, _ FileAccess.Write) Dim w As New StreamWriter(fs) w.WriteLine("----- Request at " + DateTime.Now.ToString()) w.Flush() newStream.Position = 0 Copy(newStream, fs) w.Close() newStream.Position = 0 End Sub Sub Copy(fromStream As Stream, toStream As Stream) Dim reader As New StreamReader(fromStream) Dim writer As New StreamWriter(toStream) writer.WriteLine(reader.ReadToEnd()) writer.Flush() End Sub End Class ' Create a SoapExtensionAttribute for our SOAP Extension that can be ' applied to an XML Web service method. <AttributeUsage(AttributeTargets.Method)> _ Public Class TraceExtensionAttribute Inherits SoapExtensionAttribute Private m_filename As String = "c:\log.txt" Private m_priority As Integer Public Overrides ReadOnly Property ExtensionType() As Type Get Return GetType(TraceExtension) End Get End Property Public Overrides Property Priority() As Integer Get Return m_priority End Get Set m_priority = value End Set End Property Public Property Filename() As String Get Return m_filename End Get Set m_filename= value End Set End Property End Class [C#] using System; using System.Web.Services; using System.Web.Services.Protocols; using System.IO; using System.Net; // Define a SOAP Extension that traces the SOAP request and SOAP // response for the XML Web service method the SOAP extension is // applied to.

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx

30-04-2009

Altering the SOAP Message Using SOAP Extensions

Page 9 of 10

public class TraceExtension : SoapExtension { Stream oldStream; Stream newStream; string filename; // Save the Stream representing the SOAP request or SOAP response into // a local memory buffer. public override Stream ChainStream( Stream stream ){ oldStream = stream; newStream = new MemoryStream(); return newStream; } // When the SOAP extension is accessed for the first time, the XML Web // service method it is applied to is accessed to store the file // name passed in, using the corresponding SoapExtensionAttribute. public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionA ttribute attribute) { return ((TraceExtensionAttribute) attribute).Filename; } // The SOAP extension was configured to run using a configuration file // instead of an attribute applied to a specific XML Web service // method. public override object GetInitializer(Type WebServiceType) { // Return a file name to log the trace information to, based on the // type. return "C:\\" + WebServiceType.FullName + ".log"; } // Receive the file name stored by GetInitializer and store it in a // member variable for this specific instance. public override void Initialize(object initializer) { filename = (string) initializer; } // If the SoapMessageStage is such that the SoapRequest or // SoapResponse is still in the SOAP format to be sent or received, // save it out to a file. public override void ProcessMessage(SoapMessage message) { switch (message.Stage) { case SoapMessageStage.BeforeSerialize: break; case SoapMessageStage.AfterSerialize: WriteOutput(message); break; case SoapMessageStage.BeforeDeserialize: WriteInput(message); break; case SoapMessageStage.AfterDeserialize: break; default: throw new Exception("invalid stage"); } } public void WriteOutput(SoapMessage message){ newStream.Position = 0; FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write); StreamWriter w = new StreamWriter(fs); string soapString = (message is SoapServerMessage) ? "SoapResponse" : "SoapReque st"; w.WriteLine("-----" + soapString + " at " + DateTime.Now); w.Flush(); Copy(newStream, fs); w.Close(); newStream.Position = 0; Copy(newStream, oldStream); }

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx

30-04-2009

] x p s a . ) 1 7 . S V ( k b e 5 4 h 3 w / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ s t n eil C e ci v r e S b e W L M X g ni dli u B | ] x p s a . ) 1 7 . S V ( 3 3 a 6 z 0 a b / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ T E N . P S A g n i s U s e ci v r e S b e W L M X g ni dli u B | ] x p s a . ) 1 7 . S V ( a 3 k y 1 a z k / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ s n oi t a cil p p A g ni r u gi f n o C | ] x p s a . ) 1 7 . S V ( z w 0 0 s 5 0 x / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e mi t e fi L e ci v r e S b e W L M X n a f o y m o t a n A | ] x p s a . ) 1 7 . S V ( o f ni d o h t e ml a c i g ol . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ of n I d o h t e Ml a ci g o L | ] x p s a . ) 1 7 . S V ( e g a t s e g a s s e m p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . t f o s o r ci m . n d s m / / : p t t h [ e g a t S e g a s s e M p a o S | ] x p s a . ) 1 7 . S V ( e t u bi r t t a n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ e t u bi r t t A n oi s n e t x E p a o S | ] x p s a . ) 1 7 . S V ( n oi s n e t x e p a o s . sl o c o t o r p . s e ci v r e s . b e w . m e t s y s / y r a r bil / s u - n e / m o c . tf o s o r ci m . n d s m / / : p t t h [ n oi s n e t x E p a o S
See Also

http://msdn.microsoft.com/en-us/library/esw638yk(vs.71,printer).aspx Altering the SOAP Message Using SOAP Extensions


// Create a SoapExtensionAttribute for the SOAP Extension that can be // applied to an XML Web service method. [AttributeUsage(AttributeTargets.Method)] public class TraceExtensionAttribute : SoapExtensionAttribute { } } void Copy(Stream from, Stream to) { TextReader reader = new StreamReader(from); TextWriter writer = new StreamWriter(to); writer.WriteLine(reader.ReadToEnd()); writer.Flush(); } public string Filename { get { return filename; } set { filename = value; } } public override int Priority { get { return priority; } set { priority = value; } } public override Type ExtensionType { get { return typeof(TraceExtension); } } } private string filename = "c:\\log.txt"; private int priority; public void WriteInput(SoapMessage message){ Copy(oldStream, newStream); FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write); StreamWriter w = new StreamWriter(fs); string soapString = (message is SoapServerMessage) ? "SoapRequest" : "SoapResponse"; w.WriteLine("-----" + soapString + " at " + DateTime.Now); w.Flush(); newStream.Position = 0; Copy(newStream, fs); w.Close(); newStream.Position = 0;

Page 10 of 10

30-04-2009