Difference between revisions of "ZSI Examples"

From PeformIQ Upgrade
Jump to navigation Jump to search
Line 307: Line 307:
Thanks and Cheers,
Thanks and Cheers,
Wolfgang
Wolfgang
======
An import's namespace must match the targetNamespace attribute of the "file" or schema being imported.
But this namespace must be different than the namespace of the schema you are importing it into.
//
<schema targetNamespace="urn:1">
<import namespace="urn:2" schemaLocation="importFile.xsd:/>
// importFile.xsd
<schema targetNamespace="urn:2">
...
-josh
</pre>
</pre>


[[Category:Python]]
[[Category:Python]]
[[Category:ZSI]]
[[Category:ZSI]]

Revision as of 16:26, 19 February 2008

Some Python ZSI Examples

CDPBilling

Python SOAP - CDP Billing

SaintBook

$ cat wsdl.sh 
#!/bin/sh

wget http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL
from ZSI.wstools import WSDLTools

...

location = 'http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL'

load = reader.loadFromURL

wsdl = load(location)
...
Not sure works for me
-josh

$ mkdir TMP
$ cd TMP/
$ wsdl2py http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL
$ ls
Maxim_client.py	Maxim_server.py	Maxim_types.py

$ python
Python 2.5.1 (r251:54863, May 23 2007, 10:06:54)
[GCC 4.0.0 20041026 (Apple Computer, Inc. build 4061)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> from ZSI.wstools import WSDLTools
 >>> location = 'http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL'
 >>> w = reader.loadFromURL(location)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
NameError: name 'reader' is not defined

 >>> reader = WSDLTools.WSDLReader()
 >>> w = reader.loadFromURL(location)
 >>> w
<ZSI.wstools.WSDLTools.WSDL instance at 0xca080>



On Jan 31, 2008, at 7:49 AM, Lorena Carlo wrote:

> Hi,
>
> I don't know if this is a ZSI bug, but for some reason I can not load
> the following webservice:
>
> http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL
>
> This is the portion of code:
>
> from ZSI.wstools import WSDLTools
> location = 'http://saintbook.org/MightyMaxims/MightyMaxims.asmx?WSDL'
> load = reader.loadFromURL
> wsdl = load(location)
>
> This is the exception I get:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File
> "c:\Python24\lib\site-packages\zsi-2.1_a1-py2.4.egg\ZSI\wstools 
> \WSDLTools
> .py", line 39, in loadFromURL
> File
> "c:\Python24\lib\site-packages\zsi-2.1_a1-py2.4.egg\ZSI\wstools 
> \Utility.p
> y", line 642, in loadFromURL
> File
> "c:\Python24\lib\site-packages\zsi-2.1_a1-py2.4.egg\ZSI\wstools 
> \Utility.p
> y", line 203, in urlopen
> File
> "c:\Python24\lib\site-packages\zsi-2.1_a1-py2.4.egg\ZSI\wstools 
> \Utility.p
> y", line 153, in urlopen
> File "c:\Python24\lib\urllib.py", line 82, in urlopen
>   return opener.open(url)
> File "c:\Python24\lib\urllib.py", line 190, in open
>   return getattr(self, name)(url)
> File "c:\Python24\lib\urllib.py", line 426, in open_file
>   return self.open_local_file(url)
> File "c:\Python24\lib\urllib.py", line 440, in open_local_file
>   raise IOError(e.errno, e.strerror, e.filename)
> IOError: [Errno 2] No such file or directory:
> '\\MightyMaxims\\MightyMaxims.asmx
> ?WSDL?65784000'
>
> Any help will be appreciated, thanks!
>
> Lorena

Building Complex Type Arrays

So grab an interpreter and import the generated module, then use  
help() to look at the request you're trying to use.   You'll probably  
see some helper methods and properties in there,

	new_
	set_
	get_

If that doesn't help provide the WSDL

-josh

On Feb 6, 2008, at 7:51 AM, Joseph Boiteau wrote:

> Hi,
>
> I'm using a ZSI client interface generated with  --complexType  
> option (ZSI 2.0)
> When I try to construct a request properly, I cannot find a nice way  
> to instantiate the array object.
>
> A simple list [] seems to correspond to the array, but then I have  
> no parent object to instantiate an array element..
>
> Using the second generated file (*_services_types.py), the element i  
> get using ns0.myDef_Def(None) is a basic object.. without specific  
> attributes or methods I need.
>
> So I'm looking after the manner to instantiate properly any sub-node  
> object.
>
> Thanks

Nilable Types

a nilled element looks like this:

  <whatever xsi:nil="true"/>


So it should be present if it is minOccurs=1 

-josh

On Feb 7, 2008, at 11:32 AM, Rex Corrovan wrote:


Hey all,

Been using ZSI a while now, and came across a 'Bad Thing™'. I would get an exception that 'Required <type> missing' any time I would make certain requests.

Upon further investigation I realized that if the WSDL I was using had nillable=true, and minOccurs=1 ZSI, and more specifically TC.py, would throw this exception if the server returned an empty element. In this case an Empty element is valid because nillable is true, and the server HAS to return this tag simply because it has minOccurs of 1.

Anyway, the fix was not to hard, on line (note: I also added the space after 'Required ' in the exception string for a better looking message)

from original Line 153:
        if not href:
            if self.minOccurs is 0: return None
            raise EvaluateException('Required' + tag + ' missing',
                    ps.Backtrace(elt))


To my patched version:
        if not href:
            if self.minOccurs is 0: return None
            if self.minOccurs is 1 and self.nillable is True: return None
            raise EvaluateException('Required ' + tag + ' missing',
                    ps.Backtrace(elt))

Namespaces

This is the wsdl for the above service:


<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2_01-hudson-189-. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.2_01-hudson-189-. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://services/" name="testserviceService">
<wsp:UsingPolicy></wsp:UsingPolicy>
<wsp:Policy wsu:Id="testservicePortBinding_testMethod_WSAT_Policy">
<wsp:ExactlyOne>
<wsp:All>
<ns1:ATAlwaysCapability xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/10/wsat" wsp:Optional="false"></ns1:ATAlwaysCapability>
<ns2:ATAssertion xmlns:ns3="http://schemas.xmlsoap.org/ws/2002/12/policy" xmlns:ns2="http://schemas.xmlsoap.org/ws/2004/10/wsat" ns3:Optional="true" wsp:Optional="true"></ns2:ATAssertion>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<types>
<xsd:schema>
<xsd:import namespace="http://services/" schemaLocation="http://localhost:8080/testserviceService/testservice?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="testMethod">
<part name="parameters" element="tns:testMethod"></part>
</message>
<message name="testMethodResponse">
<part name="parameters" element="tns:testMethodResponse"></part>
</message>
<portType name="testservice">
<operation name="testMethod">
<input message="tns:testMethod"></input>
<output message="tns:testMethodResponse"></output>
</operation>
</portType>
<binding name="testservicePortBinding" type="tns:testservice">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="testMethod">
<wsp:PolicyReference URI="#testservicePortBinding_testMethod_WSAT_Policy"></wsp:PolicyReference>
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="testserviceService">
<port name="testservicePort" binding="tns:testservicePortBinding">
<soap:address location="http://localhost:8080/testserviceService/testservice"></soap:address>
</port>
</service>
</definitions>




(This code directly incooperates an EJB, but without this, directly having the code in the WebMethod shows the same result.)


Using wsdl2py I got:


wn@omega:~$ wsdl2py --url http://localhost:8080/testserviceService/testservice?wsdl
Error loading http://localhost:8080/testserviceService/testservice?wsdl: 
namespace of schema and import match
wn@omega:~$ 


Using the ServiceProxy module directly in the code shows the same result.






Could someone give me a hint what's wrong here?

======
From your wsdl .....


<xsd:import namespace="http://services/" schemaLocation="http://localhost:8080/testserviceService/testservice?xsd=1"></xsd:import>




Take a look at the schema file you are importing and the default namespace in that document. This should match the value of the namespace in your import statement above.


======
certainly it is a stupid failure, but I'm unable to bring it to work: a WebService provider coded using Netbeans with J2EE 1.5 and the client with ZSI:


wn@omega:~$ wsdl2py --url http://localhost:8080/testserviceService/testservice?wsdl
Error loading http://localhost:8080/testserviceService/testservice?wsdl: 
namespace of schema and import match
wn@omega:~$ 


Using the ServiceProxy module directly in the code shows the same result.








From your wsdl .....

  <xsd:import namespace="http://services/" schemaLocation="http://localhost:8080/testserviceService/testservice?xsd=1"></xsd:import>

======

Take a look at the schema file you are importing and the default namespace in that document. This should match the value of the namespace in your import statement above.

Are you actually sure? The error-message is "namespace of schema and import match". I read this as "it is equal and that is an error". An indeed the condition in XMLSchema.py of ZSI  to raise this exception is an equal between two variables.

Furthermore, when I edit the wsdl-file manually and modify the namespace attribute of the import tag to something different then the targetNamespace given at the top of the file, I got the exception: import schema bad targetNamespace

Can you point my directly to the piece of xml I have to modify, since I didn't got it by now.

Thanks and Cheers,
Wolfgang

======
An import's namespace must match the targetNamespace attribute of the "file" or schema being imported.

But this namespace must be different than the namespace of the schema you are importing it into.

// 
<schema targetNamespace="urn:1">

<import namespace="urn:2" schemaLocation="importFile.xsd:/>

// importFile.xsd
<schema targetNamespace="urn:2">
...

-josh