Skip to Content.
Sympa Menu

devel - [sympa-dev] Help with developing a new Soap Service

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: Andrew Chilton <address@concealed>
  • To: address@concealed
  • Subject: [sympa-dev] Help with developing a new Soap Service
  • Date: Tue, 2 Aug 2011 10:35:39 +1200

Hi everyone,

Over the past couple of months I've been developing some new Soap
services for Sympa. It all seemed to be going quite well until I got
PHP involved. As an example let me show you an example of calling a
'getUserPrefs' service with both Perl and PHP. In summary the Perl
version keeps the key names and PHP throws them away and starts
indexing from 0 (however this numbering isn't consistent per field).

See the attached file for these examples, excerpts from sympa.wsdl and
the relevant part of sympasoap.pm.

Does anyone know how to do this in PHP and does it depend on what I
have got in my sympa.wsdl file. The Perl version doesn't read the WSDL
file but the PHP code does (though sometimes it seems to care about
what's in it and in other cases it doesn't seem to care at all).

I could revert to using a return array with positional parameters but
I think named parameters are nicer. I'm pretty close to just going
with this option but thought I'd try the list and see what people
think.

Many thanks.

Cheers,
Andy

--
Andrew Chilton
e: address@concealed
w: http://www.appsattic.com/
p: +64 21 891 681
##
----------------------------------------------------------------------------
# examples from Perl/PHP

$ soap-test.pl getUserPrefs
{ expiration => 15, gecos => "APC", language => "en_US" }

$ soap-test.php getUserPrefs
Array
(
[0] => en_US
[1] => APC
[2] => 15
)

##
----------------------------------------------------------------------------
# in sympa.wsdl

<!-- types part -->

<complexType name="prefsType">
<all>
<element name="gecos" minOccurs="0" type="string"/>
<element name="language" minOccurs="0"
type="string"/>
<element name="expiration" minOccurs="0" type="int"/>
</all>
</complexType>

<!-- message part -->
<message name="getUserPrefsRequest">
</message>

<message name="getUserPrefsResponse">
<part name="return" type="tns:prefsType"/>
</message>

<!-- portType part -->

<operation name="getUserPrefs">
<input message="tns:getUserPrefsRequest" />
<output message="tns:getUserPrefsResponse" />
</operation>

##
----------------------------------------------------------------------------
# in sympasoap.pm

sub _check_valid_sender {
my ($class, $sender) = @_;
unless ($sender) {
die SOAP::Fault->faultcode('Client')
->faultstring('User not authentified')
->faultdetail('You should login first');
}
}

sub _getUser {
my ($class, $email) = @_;
my $user;
unless ( $user = &List::get_user_db($email) ) {
die SOAP::Fault->faultcode('Client')
->faultstring('Not allowed.')
->faultdetail("User is not logged in.");
}
return $user;
}

sub getUserPrefs {
my ($class) = @_;
# no other inputs, just that the person is logged in

my $sender = $ENV{'USER_EMAIL'};
my $robot = $ENV{'SYMPA_ROBOT'};

&Log::do_log( 'info', 'SOAP : getUserPrefs() for %s (%s)', $sender,
$robot );

# check that this person is authenticated
$class->_check_valid_sender( $sender );

# make sure this person exists
my $user = $class->_getUser( $sender );

# return these values
my $prefs = {
gecos => $user->{gecos},
language => $user->{lang},
expiration => $user->{cookie_delay},
};
return SOAP::Data->name('result')->value( $prefs );
}

##
----------------------------------------------------------------------------


  • [sympa-dev] Help with developing a new Soap Service, Andrew Chilton, 08/01/2011

Archive powered by MHonArc 2.6.19+.

Top of Page