Finding What Is Being Returned in the Response from a Web Service

We already know that to find out what we're expected to send in a request to a web service, we need to look in the service's helper module, which contains classes for all request objects, but how do we know what we are receiving as a response?

If we look again at the login method in the Binding class, we will find that it returns an object of the loginResponse type, as shown in Listing 2-16.

Listing 2-16. The return value from the Binding class def login(self, request): [...]

typecode = Struct(pname=None, ofwhat=loginResponse.typecode.ofwhat, pyclass=loginResponse.typecode.pyclass) response = self.binding.Receive(typecode) return response

From the loginResponse class (Listing 2-17), we find that it contains only one variable, _return.

Listing 2-17. The contents of the loginResponse class class loginResponse:

self._return = None returnloginResponse.typecode Struct(pname=("urn:NSConfig","loginResponse"),^ ofwhat=[ns0.simpleResult_Def(pname="return", aname="_return", typed=False, encoded=None,^

minOccurs=1, maxOccurs=1, nillable=True)], pyclass=loginResponse, encoded="urn:NSConfig")

Yet this is not enough, as _return is the object that contains the information we require, and we need to find out how to reference it. Since loginResponse is very simple (only two fields returned), it uses a generic response object, and we find that from the typecode setting for the loginResponse class, by looking at the ofwhat setting in the class' typecode definition. In the following example it is the highlighted string:

class loginResponse:

self._return = None return loginResponse.typecode = Struct(pname=("urn:NSConfig","loginResponse"), ofwhat=[ns0.simpleResult_Def(pname="return", aname="_return", typed=False, encoded=None, minOccurs=1, maxOccurs=1, nillable=True)], pyclass=loginResponse, encoded="urn:NSConfig")

More complex structures have Result objects named after them, so it is easier to find them, but with login we need to look for the simpleResult class in the types definition module (NSStat_services_types. py). This class definition, shown in Listing 2-18, may look a bit cryptic, but we do not really need to know the details of its functioning; just look for the Holder class definition.

Listing 2-18. The class definition for simpleResult class simpleResult_Def(ZSI.TCcompound.ComplexType, TypeDefinition): [...]

class Holder:

# pyclass self._rc = None self._message = None return

I will explain in more detail how to find references and definitions of the objects for complex data types later in this chapter in the "Reading System Health Data" section.

Was this article helpful?

0 0

Post a comment