views:

57

answers:

3

I am not using Visual Studio 2010. I have a class file that I marked as a webmethod. I am able to compile it using C# compiler targetting the .NET 3.5 framework.

How can I make this a webservice? Any ideas?

A: 

First, make sure that your class inherits from WebService. Then add a new WebService ASMX file/class to your project. Have the new class inherit your main class. You;ll then be able to access the new webservice through a the url. ex, http://example.com/WebService.asmx

jojaba
A: 

Generally a WebService is configured automatically when you use it as a Web project. For normal class library, it is better to use WCF classes and mark using OperationContract for the class.

Configuring a class library is also very easy in case of WCF.

abhishek
How do you do that without Visual Studio? I am using Notepad++ for my development.
abhi
@abhi: why? Visual Studio Express 2010 is free.
John Saunders
If you still want to use only Notepad, you need to create Soap request body from the client and Request the server and also parse Soap response body which you get from the server. You need to use wsdl to parse to the members.
abhishek
+1  A: 

In general, this is a bad idea.

A web service is generally designed to operate in a Service-Oriented manner. It expects to be called across a network, and is designed with that in mind.

A class is generally designed to operate in a the same process as the callers of its methods. For instance, calling the methods of a class is usually inexpensive, so it makes sense to design the class with many fine-grained methods. Calling a web service is generally more expensive because the calls will usually go across a network. It makes better sense to design the service with fewer, course-grained methods.

A web service should usually be designed to be stateless. A class, in general, can maintain state. An example would be a class that represents a bank account. It makes perfect sense for such a class to maintain a running total of the account balance, and to change that total when Deposit and Withdraw methods are called. However, you would not want to call Deposit and Withdraw for every transaction across a network. Instead, you might send the service a list of Transaction objects, each representing a Deposit or Withdrawal. You would send the list to the service in a single operation, rather than calling across the network many times.

John Saunders