views:

239

answers:

4

I'm planning to write a web service aka api for my application which was developed with .Net and SQLServer. .Net provides a simple way to create webservices by creating asmx files. But i need to know how best it can be designed or what are the best practices in creating a web service in .net or some pointers to good articles as this is my first experience in web services programming. Eventhough SF has many references to best practices in API (which are very good) i dont find much information oriented for .net webservices.

Update: After dariom's reply i would like to mention that i'm doing it in .net 2.0

+4  A: 

It's not easy to remember all the best practices out there, but here is my advice:

  • Avoid using data types which aren't easily serializable or aren't compatible with the WS standards (and thus you won't be able to consume the service using different languages). Most notably are RecordSets and other MS-only reference types.
  • Notice there's a difference between static web service (a static method which has [webmethod]) and non-static (memeber function). This might affect your performance and resource usage.
  • There's a difference between designing a .NET webservice that runs inside your intranet, and a webservice designed for the internet. The second should be simpler in that the XML data that goes on the wire should be much smaller.
  • I guess the webservice is going to deployed on an IIS server. Notice there's a difference in authentication when running inside the intranet and on the internet. You might need to use impersonation for the service to be able to do specific tasks.

I guess there's much much more, better look for some documentation discussing that.

Moshe
KISS - Keep It Simple Stupid This really applies to web services. 1. There is a client waiting breathlessly for the result. 2. There are multiple clients wanting to call your gem called code.
Brad Bruce
A: 

If you're using .NET 3.0 or later I would encourage you to consider implementing your service using WCF.

The learning curve is steeper, but you'll benefit from the flexibility and features that WCF offers. With WCF you can make your service compatible with ASMX services (regular .NET web services) so other applications and other languages can consume the service as though it was a regular .NET web service.

There are lots of resources to help you get started. Try MSDN, Learning WCF and Programming WCF Services.

dariom
@dariom: I would love to, but i'm stuck with .net 2.0
blntechie
A: 

There's a book of design patterns for .NET ASMX web services here: http://msdn.microsoft.com/en-us/library/ms978729.aspx

It describes the following design patterns:

Entity Aggregation Process Integration Portal Integration Data Integration Function Integration Service-Oriented Integration Presentation Integration Message Broker Message Bus Publish/Subscribe Pipes and Filters Gateway

Geoff Snowman
+2  A: 

We are developing web service starting from XSD schema first (contract first). Also we are using Thinktecture’s WSCF - Web Services Contract First tool to generate web service interfaces. It worked for us pretty good for last 2 years.

They also have good walk through on how to use there tool. http://www.thinktecture.com/resourcearchive/tools-and-software/wscf/wscf-walkthrough

Vlad N