Python
This page provides a code sample for connecting to xWeb with Python. This code calls the Authenticate and Execute methods.
This code sample employs the suds library located at https://fedorahosted.org/suds.
Example of ExecuteMethod
from suds import WebFault
from suds.client import Client
##Consuming the wsdl
client = Client('http://mynetformsite.org/xweb/secure/netforumxml.asmx?wsdl')
print client
### Authentication - replace with xWeb Login's username and password
print client.service.Authenticate('xWebUserName','xWebPassword')
print client.last_sent()
token = client.last_received().getChild("soap:Envelope").getChild("soap:Header").getChild("AuthorizationToken").getChild("Token").getText()
authToken = client.factory.create('AuthorizationToken')
authToken.Token = token
print authToken
client.set_options(soapheaders=authToken)
print client.service.GetVersion()
### Creating a Parameter[] object to provide to ExecuteMethod
parameter = client.factory.create('Parameter')
parameter.Name = 'exb_code'
parameter.Value = '2011SHOW'
array_of_parameter = client.factory.create('ArrayOfParameter')
array_of_parameter[0].append(parameter)
print array_of_parameter
# Ok here goes nothing… making the call to get the exhibitor info.
print client.service.ExecuteMethod('ExhibitorInformation','GetExhibitorInformation',array_of_parameter)
# To check the request
print client.last_sent()
Example of UpdateFacadeObject
# -*- coding: utf-8 -*-
from suds import WebFault
from suds.client import Client
from suds.sax.element import Element
# First set up the client
client = Client('http://www.yournetforumsite.org/xweb/secure/netforumxml.asmx?wsdl')
client.set_options(prettyxml=True)# This is required due to a bug in suds
# Authenticate
print client.service.Authenticate('username','password')
# Get authentication token
token = client.last_received().getChild("soap:Envelope").getChild("soap:Header").getChild("AuthorizationToken").getChild("Token").getText()
#print token
# Setting the received token as part of the header for future requests
authToken = client.factory.create('AuthorizationToken')
authToken.Token = token
# Setting up the header to contain the auth. token
client.set_options(soapheaders=authToken)
# Checking to see if contact is made
#print client.service.GetVersion()
onode = Element("ns1:oNode")
orgs = Element('OrganizationObjects')
org = Element('OrganizationObject')
data = Element('org_products_ext').setText("Whatever you want to set")
org = org.append(data)
orgs = orgs.append(org)
onode = onode.append(orgs)
response=None
org_key = 'E2E65B9A-5FAB-40D2-9819-6ABC08A49848'
try:
response = client.service.UpdateFacadeObject('Organization', org_key, onode)
except WebFault, f:
print str(response)
print f.message
print response
Acknowledgment
Thank you to Pradnya Devare for contributing this code sample.
More example code
#!/usr/bin/python
from suds import WebFault
from suds.client import Client
import logging
logging.basicConfig(filename='suds.log',level=logging.INFO)
### Extra logging if needed
#logging.getLogger('suds.client').setLevel(logging.DEBUG)
#logging.getLogger('suds.transport').setLevel(logging.DEBUG)
### Consuming the wsdl
client = Client('http://somewhere.org/xwebpartner/Secure/netforumXML.asmx?wsdl',faults=False,autoblend=True)
logging.info(client)
### Authentication - replace with xWeb Login's username and password
logging.info( client.service.Authenticate('xWeb_username','xWeb_password'))
client.last_sent()
token = client.last_received().getChild("soap:Envelope").getChild("soap:Header").getChild("AuthorizationToken").getChild("Token").getText()
logging.info ('token: ' + token )
authToken = client.factory.create('AuthorizationToken')
authToken.Token = token
client.set_options(soapheaders=authToken)
### See if we can do anything
#logging.info(client.service.GetVersion() )
#client.service.GetDateTime()
#client.last_received()
### These seemed to be broken on the server. Why?
#client.service.WEBCommitteeGet()
#client.service.ExecuteMethod()
#client.last_sent()
#client.last_received()
### Create a query for the GetQuery method
q = client.factory.create('GetQuery')
q.szObjectName = 'Individual'
q.szColumnList = 'ind_first_name,ind_last_name,ind_spouse_name,ind_full_name_cp'
# suds automatically encodes the (') to (') - Don't worry, that's OK.
q.szWhereClause = "ind_last_name LIKE 'SX%'"
#q.szWhereClause = "ind_cst_key ='xxxx-xxxxxxxxxx-xxxxxxxxx-xxxxxxxx'"
q.szOrderBy = 'ind_last_name'
### Put the query in an array
z=[]
z.append(q)
client.service.GetQuery(z)
r=client.last_received()
#logging.info(r)
### Pull out the stuff we want to use
result= r.getChild("soap:Envelope").getChild("soap:Body")[0][0][0]
#i=result[0][0][0][0]
for i in result:
print i.getChild('ind_full_name_cp').text,i.getChild('ind_first_name').text,i.getChild('ind_last_name').text,i.getChild('ind_cst_key').text
Acknowledgment
Thank you to Rotary District 5110 for contributing this code sample.