tags:

views:

97

answers:

4
+1  Q: 

c#.net web service

i want to create a simple webservice , and i want to call that webservice from a client program using c#.net. As i am a beginner, i find it difficult to do it. can anybody help.

Thank you...

+2  A: 

Create a file with extension asmx. Provide your function that is to be exposed, as a [WebMethod].

[WebMethod]
public string HelloWorld()
{
    return "Hello World";
}

from your other application add a web reference to the currently built asmx page. From that reference you will be able to invoke the desired function.

rahul
+1..the best answer so far
jjj
+1  A: 

If you're just learning about web services, I'd recommend against going the ASMX/WebService/WebMethod route. That functionality has been superseded by WCF.

WCF Getting Started Tutorial

WCF 101 (very simple example)

Aaronaught
A: 

I'm basically in a same situation as you, so I'll share what I've thought of so far. I haven't really implemented anything like you described yet (just a simple web app), so consider this a thought experiment and the preliminary results of my research.

To create the web service, I thought using Google App Engine would be the easiest thing to do. It's free, and pretty easy to understand and use even for a beginner. They have a lot of tutorials too. Their datastore is also easy to use. You have to write your code in Python + Django templates or Java, and although I had never used python or django before, I found them amazingly quick and easy to learn the basics. There's also an Eclipse plugin for it.

From what I've seen, you create a structure of URLs to your resources (the data you want to access from your web service. For example /planets/earth. You map these URLs to WebRequestHandlers in your google apps code. In your code, you "handle" a message from some client through one of the HTTP methods like GET or POST. Depending on the method, you perform some programming task to prepare the data and then send back a response. For example, maybe you set it up so that you return the diameter of earth when you someone GETs /planets/earth.

Then, in your application you can send and receive stuff from your web service using System.Net.HttpWebRequest. This is the part I have never done, but I think you just create and instance of HttpWebRequest, give it the appropriate info like URL, Method, data to send, etc, then send the web request on it's way. You get the response and do something with it in your program.

Well, that's an overview of what I've found so far, and I hope it's helpful (and not wrong)!

Benny Jobigan