C# Client to Consume Google App Engine RESTful Webservice (rpc XML)

Posted by Ngu Soon Hui on Stack Overflow See other posts from Stack Overflow or by Ngu Soon Hui
Published on 2010-04-23T09:05:02Z Indexed on 2010/04/23 9:53 UTC
Read the original article Hit count: 441

Filed under:
|

I think I hit a problem when using C# client to consume Google App Engine Webservice. The Google App Engine code I use is here. This is how the python script on server would look like:

from google.appengine.ext import webapp                                        
from google.appengine.ext.webapp.util import run_wsgi_app                      
import logging                                                                 

from StringIO import StringIO                                                  
import traceback
import xmlrpclib
from xmlrpcserver import XmlRpcServer

class Application:
    def __init__(self):
        pass                    

    def getName(self,meta):                                                    
        return 'example'

class XMLRpcHandler(webapp.RequestHandler):                                    
    rpcserver = None

    def __init__(self):         
        self.rpcserver = XmlRpcServer()                                        
        app = Application()                                                    
        self.rpcserver.register_class('app',app)                               

    def post(self):
        request = StringIO(self.request.body)
        request.seek(0)                                                        
        response = StringIO()                                                  
        try:
            self.rpcserver.execute(request, response, None)                    
        except Exception, e:                                                   
            logging.error('Error executing: '+str(e))                          
            for line in traceback.format_exc().split('\n'):                    
                logging.error(line)
        finally:
            response.seek(0)  

        rstr = response.read()                                                 
        self.response.headers['Content-type'] = 'text/xml'                     
        self.response.headers['Content-length'] = "%d"%len(rstr)               
        self.response.out.write(rstr)

application = webapp.WSGIApplication(                                          
                                     [('/xmlrpc/', XMLRpcHandler)],
                                     debug=True)                               
def main():
  run_wsgi_app(application)                                                    

if __name__ == "__main__":
    main()

The client side ( in Python) is this:

import xmlrpclib
s = xmlrpclib.Server('http://localhost:8080/xmlrpc/')
print s.app.getName()

I have no problem in using Python client to retrieve values from Google App Engine, but I do have difficulties in using a C# client to retrieve the values. The error I got was 404 method not found when I am trying to GetResponse from the web request.

This is my code

        var request = (HttpWebRequest)WebRequest.Create("http://localhost:8080/xmlrpc/app");

        request.Method = "GET";
        request.ContentLength = 0;
        request.ContentType = "text/xml";
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) //404 method not found error here.
        {

        }  

I think it must be that the url is wrong, but I don't know how to get it right. Any idea?

© Stack Overflow or respective owner

Related posts about c#

Related posts about google-app-engine