0

I am developing one webservice using c#.It is possible intercept the client request using Filter(Using HttpModule).But how it is possible to modify the request.I can get request like this

 Stream InputStrm = App.Context.Request.InputStream;

i want to decrypt the request&Set it back.How can i do this??

user922834
  • 195
  • 2
  • 6
  • 18

1 Answers1

1

It depends on the web service technology you're using. If you're using Web API or MVC, you use an ActionFilter. If you're using asmx, you use a SoapExtension. If you're using WCF, you have various extension points. If it's just a web request, an HttpModule can apply a filter by saying HttpContext.Current.Response.Filter = new SomeFilter( HttpContext.Current.Response.Filter ) where SomeFilter is a class like public class SomeFilter : Stream {. Request.Filter should work the same way. http://www.15seconds.com/issue/020417.htm is an old article, but shows a bit about these Response.Filter classes.

robrich
  • 13,017
  • 7
  • 36
  • 63
  • I am using asmx.Using SoapExtension it is possible.In filter i decrypting the request for checking Headers and authentication.If we using soapExtension we have to specify decryption attribute above the webmethod.So decryption is happening twice(In filter and in WebService Method).I want to avoid this.If i can able to modify the request in filter,decryption will happen only once – user922834 May 16 '12 at 06:37
  • Then in the soap extension, decrypt, and write the decrypted value to the stream passed into the method. Inside method, you can assume the content is already decrypted. – robrich May 16 '12 at 15:06
  • Actually using soaping extension,directing calling DecryptSoap() function.it will return a memorystream.It will not modify the request.I am doing this only for processing the request.We can't able to put decrypt attribute above corresponding filter method like that we doing in webmethod.Currently i am doing like this ..EncryptionExtension ObjCrypto = new EncryptionExtension();MemoryStream MemStrm = ObjCrypto.DecryptSoap(InputStrm); – user922834 May 17 '12 at 12:18
  • http://msdn.microsoft.com/en-us/library/esw638yk(v=vs.71).aspx scroll down to `public override Stream ChainStream( Stream stream ){` – robrich May 17 '12 at 18:04