开发者

Using Generic Methods with a WebService like WCF or ADO.NET Data Services

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 A开发者_如何学PythonDO.NET DS?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜