views:

288

answers:

1

Is it possible to use generic methods with WCF or ADO.NET DS?

Or is it possible to create a generic WebService Repository with WCF or ADO.NET DS?

+2  A: 

The answer is "mu".

You're thinking about it wrong.

WCF - or web services in general - is not about exposing methods. It's about exposing a data or message contract.

Design a service by designing the messages that get exchanged, not the class interface.


There are several ways to go about designing the messages:

  1. If you have XML tools, and speak XSD, you might want to design an XML Schema for the input and output messages. Then embbed that into a WSDL, and use svcutil to generate the WCF stub or proxy.

  2. If you have a good vision for what the XML should look like, you can just create sample input + output messages, then "Derive" or infer the XSD from those messages using something like the XSD.exe tool in the .NET SDK. The inferred XSD is not always exactly what you want - often it is not general enough if you start from a single message. But it gets you started. Once you have the XSD, you can go to step 1. Actually, step 1 and 2 can be iterative.

  3. Design the data contract classes using the DataContract attribute .

  4. Same thing, using the MessageContract attribute.

  5. use a tool like WSCF.

There are other articles on the blogs on MSDN that describe the approach and go into more details about the above options.

Cheeso
Can you give a little example of "designing the messages"?
Rookian
added to the answer
Cheeso
If I get you right, I have to design a message that can contain a list of Customers or a list of Products. So a message has to been designed that fits to all kind of lists (in my stupid example), right? So background is I want to use a kind of generic repository for avoiding redundance code.
Rookian
Yes, that's right. And that's entirely possible with XSD or with DataContract.
Cheeso
thanks for your short answeres :)
Rookian