user1153896
user1153896

Reputation: 303

Best way to create python web service and c# client application

I am looking for a simple and reliable way to create Python Web Service and consume it from the .Net (c#) application.

I found plenty of different libraries, where one is better than another, but nobody seems to have a complete working example with Python Web Service and some simple c# client. And reasonable explanations of steps to configure and run

Upvotes: 1

Views: 3473

Answers (2)

Maciek Talaska
Maciek Talaska

Reputation: 1638

I am suggesting using Tornado. It is very simple to use, non-blocking web-server written in Python. I've been using it in the past and I was shocked how easy it was to learn and use it.

I am strongly encouraging you to design your API with REST in mind. It will make your API simple, and easy to consume by any language/platform available.

Please, have a look at the 'Hello World' sample - it has been taken from Torando's main site:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

As for the client part - there is nothing complicated:

string CreateHTTGetRequest(string url, string cookie)
{
    WebRequest request = WebRequest.Create(url);
    request.Method = "GET";
    request.Headers.Add("Cookie", cookie);

    WebResponse response = request.GetResponse();
    Stream stream = response.GetResponseStream();
    StreamReader reader = new StreamReader(stream);
    string content = reader.ReadToEnd();
    reader.Close();
    response.Close();
    return content;
}

In case the server is running on your local machine, the URI is: 'http://localhost:8888/'

Upvotes: 2

pylover
pylover

Reputation: 8075

you may start your practice by:

  1. Install ZSI
  2. Create a WSDL for your service

The full example

4.On client(C#) follow this tutorial

Upvotes: 0

Related Questions