views:

53

answers:

2

Hello, I have a basic asp.net webservice that returns a simple response. To make it ucore compliant I need to apply an XSLT. Is there a way to apply an XSLT to my response?

I'm aware the receiver can apply it on their end, but in this scenario I need to apply it on my end.

Thanks!

A: 

Whether you're talking about legacy ASMX or the current WCF web services, you're talking about controlling the serialized XML on output. Both the ASMX and WCF handlers by default will fire the serialization routines for the underlying objects used in their respective web service methods.

You could do it if you want to work outside the construct of serialized XML. Your method could return a string which is nothing more than the output of your method. You would need to:

  1. Go through the logic of building your resultant object
  2. Serialize the object to XML -- as a string
  3. Run an XSL transformation on the XML to an output stream
  4. Return the output stream's contents from your method

This is an extremely lousy hack, though.

EDIT: per John's reference, focus on solving this through control of the output XML. If you're using legacy ASMX, this is basic XML serialization. If you're using WCF, there are greater formatting options available.

jro
-1 for suggesting XML serialization, especially in the context of WCF.
John Saunders
John, WCF is serializing XML under the covers. See DataContractSerializer. My comment was generic -- focus on controlling the xml output, not incorporating XSLT.
jro
@jro: sorry, I thought you were referring to the XmlSerializer.
John Saunders
@john: oy, forgot about that thing. I'm trying to put it out of my mind for good. :-)
jro
A: 

See Custom Message Formatters.

Ignore ASMX web services. They have very little extensibility and are now considered to be "legacy technology" by Microsoft.

John Saunders
Thanks John, "legacy" you're probably right. But you have to admit they are super easy and quick, it's nice to be able to setup and working service in < 5 minutes.
aron
@aron: it's exactly as quick to set up a WCF service, and you'll find it _much_ harder to do what you want using ASMX services. BTW, "legacy" also means they're only fixing critical bugs. That means they're not fixing any bug you want to have fixed.
John Saunders