4

I am trying to dynamically modify XML data in SOAP requests to ASMX services.

I overrided GetWebRequest() method in SoapHttpClientProtocol class in order to read and modify XML data that the RequestStream contains.

The problem is, the request seems to be empty, there is no data in it whatsoever. Is this because the SOAP data hasn't yet been generated and serialized or am I doing something wrong?

Yahia
  • 69,653
  • 9
  • 115
  • 144
Vex
  • 1,179
  • 3
  • 15
  • 24
  • 1
    Most likely, have you tried overriding [GetWebResponse](http://msdn.microsoft.com/en-us/library/8415zzb7.aspx) instead? – Justin Nov 15 '11 at 13:56
  • Nope, it's GetWebRequest. Maybe my understanding of the method is flawed though... is it possible that it occurs before the actual SOAP data is set? It would certainly seem that way. – Vex Nov 15 '11 at 14:04
  • 2
    My interpretation of the documentation was that GetWebRequest would return an empty web request (for a given url) to be populated. The GetWebResponse method is then called in order to get the actual response after the request object has been "populated" with the SOAP request body, so this would be the place to modify it. – Justin Nov 15 '11 at 14:10
  • You are absolutely right. This is the correct method after all, the request object is already fully populated when the method enters. Thanks. – Vex Nov 15 '11 at 14:25

1 Answers1

2

What you need is a SoapExtension. You could hook into the SoapMessageStage.AfterSerialize stage in ProcessMessage to modify your soap message. I've done this in the past to add WSSE headers in situations where I couldn't add a dependency on Microsoft's WSE library (since it isn't available for Mono).

Complete tutorial here: http://msdn.microsoft.com/en-us/magazine/cc164007.aspx

GetWebRequest is too early for your purpose, GetWebResponse is too late.

Yahia
  • 69,653
  • 9
  • 115
  • 144
Anash P. Oommen
  • 607
  • 3
  • 10