def main(): user = User('john_doe', 'John Doe', 25) nsdict = {'types': 'http://pycon.org/types'} registration = ServiceProxy('../binding.wsdl', nsdict=nsdict, tracefile=sys.stdout) response = registration.RegisterUser(user) print(response)
def main(): server = ServiceProxy('../binding.wsdl', typesmodule=MyComplexTypes, tracefile=sys.stdout) user = server.GetUser('john_doe') print ' Age: %d' % user.Age print ' Name: %s' % user.Name print 'UserId: %s' % user.UserId
def main(): # How to programatically create a WSDL ################################### ws = WSDL("urn:gosa.wsdl") gp = ws.addPortType("addPortType") mi = ws.addMessage("addInput") mi.addPart("x", ("http://www.w3.org/1999/XMLSchema", "integer")) mi.addPart("y", ("http://www.w3.org/1999/XMLSchema", "integer")) mo = ws.addMessage("addOutput") mo.addPart("result", ("http://www.w3.org/1999/XMLSchema", "integer")) op = gp.addOperation("add") op.setInput("addInput") op.setOutput("addOutput") bd = ws.addBinding("addBinding", ("urn:gosa.wsdl", "addPortType")) bd.addExtension(SoapBinding("http://schemas.xmlsoap.org/soap/http", "rpc")) opb = bd.addOperationBinding("add") opb.addExtension(SoapOperationBinding("add")) opb.addInputBinding(SoapBodyBinding("encoded", namespace="http://schemas.xmlsoap.org/wsdl/soap/")) opb.addOutputBinding(SoapBodyBinding("encoded", namespace="http://schemas.xmlsoap.org/wsdl/soap/")) sv = ws.addService("addService") svp = sv.addPort("addPort", ("urn:gosa.wsdl", "addBinding")) svp.addExtension(SoapAddressBinding("command")) ws.toDom() #print ws.document.toprettyxml() ########################################################################## # How to inspect WSDL #################################################### #wsdl = wstools.WSDLTools.WSDLReader().loadFromString(ws.document.toxml()) #service = wsdl.services[0] #for port in service.ports: # for item in port.getPortType().operations: # callinfo = wstools.WSDLTools.callInfoFromWSDL(port, item.name) # ret = "(void)" # if len(callinfo.outparams) > 0: # ns, type = callinfo.outparams[0].type # ret = "(%s)" % type # params = [] # for param in callinfo.inparams: # ns, type = param.type # params.append("%s %s" % (type, param.name)) # print ("%s " + callinfo.methodName + "(%s)") % (ret, ", ".join(params)) ########################################################################## # How to use WSDL, AMQP and to ServiceProxy wsdl = 'http://dyn-muc-50/gosa.wsdl' proxy = ServiceProxy(wsdl, transport=AmqpConnection(None)) print proxy.add(5, 6)
def get_lyrics_thread(self, callback, artist, title): # FIXME locking... global ServiceProxy if ServiceProxy is None: try: from ZSI import ServiceProxy # Make sure we have the right version.. if not hasattr(ServiceProxy, 'ServiceProxy'): ServiceProxy = None except ImportError: ServiceProxy = None if ServiceProxy is None: self.call_back( callback, None, None, error=_("ZSI not found, fetching lyrics support disabled.")) return # FIXME locking... if self.lyricServer is None: wsdlFile = "http://lyricwiki.org/server.php?wsdl" try: self.lyricServer = True timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) self.lyricServer = ServiceProxy.ServiceProxy( wsdlFile, cachedir=os.path.expanduser("~/.service_proxy_dir")) except: self.lyricServer = None socketsettimeout(timeout) error = _("Couldn't connect to LyricWiki") self.call_back(callback, error=error) return try: timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) lyrics = self.lyricServer.getSong( artist=self.lyricwiki_format(artist), song=self.lyricwiki_format(title))['return']["lyrics"] if lyrics.lower() != "not found": lyrics = misc.unescape_html(lyrics) lyrics = misc.wiki_to_html(lyrics) lyrics = lyrics.encode("ISO-8859-1") self.call_back(callback, lyrics=lyrics) else: error = _("Lyrics not found") self.call_back(callback, error=error) except: error = _("Fetching lyrics failed") self.call_back(callback, error=error) socketsettimeout(timeout)
def main(): server = ServiceProxy.ServiceProxy('../wsdl/binding.wsdl', use_wsdl=True) print ' Sending: %s' % MESSAGE response = server.echo(Message=MESSAGE) print 'Response: %s' % response['Message'] one = 1 two = 2 response = server.add(One=one, Two=two) #response = server.add(One=one) print 'Response: %s' % response['Result']
def main(): server = ServiceProxy('../binding.wsdl', use_wsdl=False) print ' Sending: %s' % MESSAGE response = server.echo(MESSAGE) print 'Response: %s' % response
def main(): server = ServiceProxy('../binding.wsdl', use_wsdl=True) print(' Sending: %s' % MESSAGE) response = server.echo(Message=MESSAGE) print('Response: %s' % response['Message'])
def get_lyrics_thread(self, search_artist, search_title, filename_artist, filename_title, song_dir): filename_artist = misc.strip_all_slashes(filename_artist) filename_title = misc.strip_all_slashes(filename_title) filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir) search_str = misc.link_markup(_("search"), True, True, self.linkcolor) edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor) if filename: # If the lyrics only contain "not found", delete the file and try to # fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki that # prevents lyrics from being found, storing the "not found" will # prevent a future release from correctly fetching the lyrics. f = open(filename, 'r') lyrics = f.read() f.close() if lyrics == _("Lyrics not found"): misc.remove_file(filename) filename = self.info_check_for_local_lyrics( filename_artist, filename_title, song_dir) if filename: # Re-use lyrics from file: f = open(filename, 'r') lyrics = f.read() f.close() # Strip artist - title line from file if it exists, since we # now have that information visible elsewhere. header = filename_artist + " - " + filename_title + "\n\n" if lyrics[:len(header)] == header: lyrics = lyrics[len(header):] gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) else: # Use default filename: filename = self.target_lyrics_filename(filename_artist, filename_title, song_dir) # Fetch lyrics from lyricwiki.org gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."), filename_artist, filename_title) if self.lyricServer is None: wsdlFile = "http://lyricwiki.org/server.php?wsdl" try: self.lyricServer = True timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) self.lyricServer = ServiceProxy.ServiceProxy( wsdlFile, cachedir=os.path.expanduser("~/.service_proxy_dir")) except: socketsettimeout(timeout) lyrics = _("Couldn't connect to LyricWiki") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) self.lyricServer = None gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) return try: timeout = socketgettimeout() socketsettimeout(consts.LYRIC_TIMEOUT) lyrics = self.lyricServer.getSong( artist=self.lyricwiki_format(search_artist), song=self.lyricwiki_format( search_title))['return']["lyrics"] if lyrics.lower() != "not found": lyrics = misc.unescape_html(lyrics) lyrics = misc.wiki_to_html(lyrics) lyrics = lyrics.encode("ISO-8859-1") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) # Save lyrics to file: misc.create_dir('~/.lyrics/') f = open(filename, 'w') lyrics = misc.unescape_html(lyrics) try: f.write(lyrics.decode(self.enc).encode('utf8')) except: f.write(lyrics) f.close() else: lyrics = _("Lyrics not found") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) except: lyrics = _("Fetching lyrics failed") gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title) gobject.idle_add(self.info_searchlabel.set_markup, search_str) gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str) socketsettimeout(timeout)