tags:

views:

39

answers:

1

I'm designing a WCF web service method that can return results either as a raw XML string, or as a structure, depending on the client's preference.

A simple approach is to have two separate methods:

MyStructure GetData();
string GetDataAsXML();

This should work fine, but given that the wire representation in both cases will be the same (or at least equivalent), I'm wondering if there's a better way to represent this in the interface? Is there an elegant way I can merge the two methods into one, for example?

+1  A: 

Umm your results will be in XML either way. One will look like this

<Response>
<SomeTags>
  <SomeTag />
  <SomeTag />
  <SomeTag />
</SomeTags>
</Response>

And the other will look like this

<Response>
<Data>
   &lt;SomeTags&gt;
      &lt;SomeTag /&gt;
      &lt;SomeTag /&gt;
      &lt;SomeTag /&gt;
   &lt;/SomeTags&gt;
</Data>
</Response>

I'd just stick with the first and let your clients figure out how they want to parse the information.

Spencer Ruport