0

The web service in question must return results of a stored procedure in SOAP XML.

I can return any object from a web service no problem, I'm even familiar with serializing JSON from an .asmx service but I'm totally stumped with the concept of returning XML from a web service who's job is to retrieve results from a stored procedure. It's very important to me this, so any help seriously appreciated.

Thankyou.

SkonJeet
  • 4,827
  • 4
  • 23
  • 32
  • MSDN Tutorials... http://msdn.microsoft.com/en-us/netframework/first-steps-with-wcf – Lloyd Feb 01 '12 at 15:20
  • this might be helpful too http://stackoverflow.com/questions/8730940/wcf-returning-streams-or-strings – kenny Feb 01 '12 at 15:24
  • I can also recommend this book http://www.amazon.com/RESTful-NET-Build-Consume-Services/dp/0596519206/ref=sr_1_1?ie=UTF8&qid=1328109932&sr=8-1 – kenny Feb 01 '12 at 15:26

2 Answers2

1

Try returning an XmlNode:

[ServiceContract]
public interface IMyService
{
    ...
    [OperationContract]
    XmlNode MyMethod(...);

    ...
}
Joe
  • 122,218
  • 32
  • 205
  • 338
  • Thanks a lot Joe, appreciate your response. So supposing the job of this service is to return the results of a stored procedure - how/where would this 'conversion' from sql result to XML occur?? Thanks again. – SkonJeet Feb 01 '12 at 15:25
  • 1
    @SkonJeet - There are many options. The simplest is to have your OperationContract return a strongly-typed result (e.g. `MyType` or `IList`) and leave the framework to do the serialization. Or you could use the Xml classes in the .NET framework to generate the XML yourself, using the data returned by your `IDataReader`. – Joe Feb 01 '12 at 15:37
  • Thanks again for your time mate. So would you say that it would be 'acceptable' for me to code a web service that fetches the results of a stored procedure into an sqlreader (as normal) and then go through and convert all this to xml using the XML classes? Or are there more 'elegant' ways of doing it? – SkonJeet Feb 01 '12 at 15:41
0

Other than returning XML as a string you can look at WCF REST http://msdn.microsoft.com/en-us/netframework/dd547388 which can be added to give you VS project templates for XML/JSON WCF projects.

kenny
  • 21,522
  • 8
  • 49
  • 87