views:

166

answers:

3

I have a WCF client proxy which reads from a SOAP web service. I do not control the service, only the client proxy. The result of invoking one of the operations of the service is defined as a very large XML schema, of which only a small subset is relevant in my application.

I have created a custom WCF behavior which allows me to parse the raw XML response and read only the relevant parts. However, the proxy still deserializes the response into an object graph (which is quite complex as a result of the XML schema). As far as my application is concerned, this last step is superfluous.

Is it possible to prevent my WCF client proxy from performing the last step of deserializing the response?

+1  A: 

Where exactly do you want to process the parts of the message you want? In general, it sounds to me like you don't really want the default client proxy generated, and you'd be better off with your own custom client proxy.

If you can go that route, one option that would be available would be to simply have the proxy return a Message object instead of a real DataContract, and then you can easily read the raw XML from the SOAP body yourself and parse it. Easier than trying to mess with the serializer, imho.

tomasr
A custom client proxy seems like a good idea. Do you have any pointers as to where to start, if I was to create my own proxy?
Tormod Fjeldskår
It's really nothing hard. Basically define your contract interface like you would for a service (just make sure all the names/namespaces match) and add the methods. Then create a class deriving from ClientBase<T> (the code for any svcutil-generated one will give you a hint, it's very easy).Dmitry's answer of how to use the Message class is good, but I'll add that you don't need to use it for both input and output... you can still used DataContracts for the request message, if you so like.
tomasr
Those are helpful tips which will get me started. Thanks a lot!
Tormod Fjeldskår
+1  A: 

Begin with defining client-side ServiceContract with operation like

[OperationContract(Action="YourAction", ReplyAction="YourResponseAction")]
Message YourMethod(Message request)

Then use generic ClientFactory to instantiate proxy.

You'll have to manually construct request Message and parse the response with a one-way reader.

Dmitry Ornatsky
A: 

I have blogged about the exact solution I ended up with. So, for completenes:

Tormod Fjeldskår