Web Services - GRISBI

joeneetscompetitiveΑσφάλεια

3 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

86 εμφανίσεις

WSDL Example

<message name="empty">


<message name="AddEntryRequest"> <part name="name"
type="xsd:string"/> <part name="address" type="typens:address"/>
</message>


<portType name="AddressBook"> <operation name="addEntry">
<input message="tns:AddEntryRequest"/> <output
message="tns:empty"/> </operation> </portType>

<service name="AddressBookService"> <port name="AddressBook"
binding="tns:AddressBookSOAPBinding"> <soap:address
location="http://localhost:8080/axis/services/AddressBook"/>
</port> </service>

Java example

After a wsdl2java transform:

// Make a service

AddressBookService service = new AddressBookServiceLocator();

// Now use the service to get a stub which implements the SDI.

AddressBook port = service.getAddressBook();

// Make the actual call

Address address = new Address(...);

port.addEntry("Russell Butek", address);


Perl example 1/2


*
Create WSDL bindings
:


perl wsdl2perl.pl
-
b base_dir URL


* Look what has been generated
.

Check the results
of the generator. There should be one
MyInterfaces/SERVICE_NAME/PORT_NAME.pm
file per port (and one directory per service).


Perl example 2/2

* Write script

use MyInterfaces::SERVICE_NAME::PORT_NAME;

my $service = MyInterfaces::SERVICE_NAME::PORT_NAME
-
>new();

my $result = $service
-
>SERVICE_METHOD();

die $result if not $result;

print $result;


SOAP messages
-

Out

*** Outgoing SOAP ******************************************************

<?xml version="1.0" encoding="UTF
-
8"?> <SOAP
-
ENV:Envelope SOAP
-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP
-
ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema
-
instance" xmlns:SOAP
-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">


<SOAP
-
ENV:Body> <ns1:getTemp xmlns:ns1="urn:xmethods
-
Temperature" SOAP
-
ENC:root="1"> <v1
xsi:type="xsd:string">90210</v1> </ns1:getTemp> </SOAP
-
ENV:Body>


</SOAP
-
ENV:Envelope>


***********************************************************************

SOAP message
-

In

* *** Incoming SOAP ******************************************************


<?xml version='1.0' encoding='UTF
-
8'?> <SOAP
-
ENV:Envelope xmlns:SOAP
-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema
-
instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">


<SOAP
-
ENV:Body> <ns1:getTempResponse xmlns:ns1="urn:xmethods
-
Temperature" SOAP
-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <return
xsi:type="xsd:float">66.0</return> </ns1:getTempResponse> </SOAP
-
ENV:Body>


</SOAP
-
ENV:Envelope>


************************************************************************


C example

#include "soapH.h" // obtain the generated stub



#include "
Temperature
.nsmap" // obtain the generated XML
namespace mapping table for the
Temperature

service



main()



{





struct

soap *soap = soap_new();




float

temp
;





if

(soap_call_ns1__get
Temp
(soap, NULL, NULL, "
90210
",
temp
) ==
SOAP_OK)





printf("
Temperature

= %g
\
n",
temp
);




else

// an error occurred





soap_print_fault(soap, stderr); // display the SOAP fault on the
stderr stream



}


Basic Authentication

Example basic authentication with PHP:

$client = new SoapClient("some.wsdl",
array('login'

=>
"some_name",

'password'

=>
"some_password"));


SOAP
Authentication

LibraryUsernameStub stub = new
LibraryUsernameStub(target);

// configure and engage Rampart


ServiceClient client =
stub._getServiceClient();


Options options = client.getOptions();


options.setProperty(RampartMessag
eData.KEY_RAMPART_POLICY,
loadPolicy("policy.xml"));


options.setUserName("
myusername
");


options.setPassword("
mypassword
");


client.engageModule("rampart");


Java example with
Axis2/Rampart module

Proxy support (Python)

if os.environ.has_key("http_proxy"):


my_http_proxy=os.environ["http_proxy"].replace("http://","")

else:


my_http_proxy=None

url = 'http://services.xmethods.net:80/soap'

n = 'urn:xmethods
-
CurrencyExchange'

server = SOAPProxy(url, namespace=n, http_proxy=my_http_proxy)


NCBI Blast exercises

Example:

Python blast: http://
www.ebi.ac.uk/Tools/services/soap/ncbiblast?wsdl

Requires python suds library: https://
fedorahosted.org
/suds/

#python
ncbiblast.py

--
verbose
--
email=MYEMAILADDRESS
--
program=
blastn

--
database=
em_rel_est_hum

--
async

--
sequence=
test.fa

>S20100921
-
101438
-
0194
-
37683217

#python
ncbiblast.py

--
verbose
--
jobid
=ncbiblast
-
S20100921
-
101438
-
0194
-
37683217
--
status

#python
ncbiblast.py

--
verbose
--
jobid
=ncbiblast
-
S20100921
-
101438
-
0194
-
37683217
--
polljob