Hi I am returning to Perl after a longish absence so apologies for any stupidness on my part.
I want to use SOAP::WSDL to manipulate some web services on a server that I own. I have installed SOAP::WSDL and successfully parsed the WSDL and created a set of classes.
I have created a simple test script using the information from the CPAN documentation that calls a web service on the server and returns some data.
I can print out the XML that is being returned with a simple print $result statement - I guess I could massage this into some Perl XML structures and process the returned data. But I think that SOAP::WSDL has already done this for me with complex types.
Here is the script:
use SG4InvInterfaces::Inventory::InventoryHttpPort; use SG4InvElements::findSubscribersResponse; use SG4InvTypes::ArrayOfSubscriber; use SG4InvTypes::Subscriber; use Data::Dumper; *SOAP::WSDL::Transport::HTTP::get_basic_credentials = sub { return ("xxxxxx", "yyyyyyyy); }; my $service = SG4InvInterfaces::Inventory::InventoryHttpPort->new(); my @subs; my $sub = SG4InvTypes::Subscriber->new(); my $result = $service->findSubscribers( { findSubscriberParams => { # SG4InvTypes::FindSubscriberPar +ams lastName => "Merwood" }, },, ); die $result if not $result; print $result->_DUMP . "\n"; print $result. "\n"; print $result->get_subscribers()->_DUMP . "\n"; print Dumper($result->get_subscribers()->get_Subscriber) . "\n"; @subs=$result->get_subscribers()->get_Subscriber; print Dumper(@subs) . "\n";
The findSubscribers method returns a SG4InvTypes::ArrayOfSubscriber within a SG4InvElements::findSubscribersResponse accessed by the get_subscribers() accessor method. I can access this using the above code and can see the structure returned:
{ 'SG4InvTypes::ArrayOfSubscriber' => { 'Subscriber' => [ bless( do{\( +my $o = 10)}, 'SG4InvTypes::Subscriber' ), bless( do{\( +my $o = 32)}, 'SG4InvTypes::Subscriber' ), bless( do{\( +my $o = 53)}, 'SG4InvTypes::Subscriber' ) ] } };
I want to iterate over the array of SG4InvTypes::Subscriber contained in this object. I can assign the array to the local array @subs which dumps as follows:
$VAR1 = [ bless( do{\(my $o = 10)}, 'SG4InvTypes::Subscriber' ), bless( do{\(my $o = 32)}, 'SG4InvTypes::Subscriber' ), bless( do{\(my $o = 53)}, 'SG4InvTypes::Subscriber' ) ];
I now want to iterate over the contents of this array and access the information from each SG4InvTypes::Subscriber' object in turn. I thought that something like the following would work::
print $result->get_subscribers()->get_Subscriber().[1]->get_firstName;
But I just get the error:
Can't call method "get_firstName" on unblessed reference at sg4test.pl + line 32.
Conceptually I want to loop over each object in the array and use the accessor methods to retrieve and update data then potentially pass the object back to the web service using the updateSubscriber class method.
Do I need to bless the array objects - please help!
The perldoc for the ArrayOfSubscriber is as follows:
NAME SG4InvTypes::ArrayOfSubscriber DESCRIPTION Perl data type class for the XML Schema defined complexType ArrayOfSubscriber from the namespace http://type.eai.ws.servicegateway.supportsoft.com. PROPERTIES The following properties may be accessed using get_PROPERTY / set_PROPERTY methods: · Subscriber METHODS new Constructor. The following data structure may be passed to new( +): { # SG4InvTypes::ArrayOfSubscriber Subscriber => { # SG4InvTypes::Subscriber accountType => $some_value, # SubscriberAccountType address => $some_value, # string address2 => $some_value, # string attributes => { # SG4InvTypes::ArrayOfSubscriberAttribute SubscriberAttribute => { # SG4InvTypes::SubscriberAttri +bute index => $some_value, # int name => $some_value, # string value => $some_value, # string }, }, billingNumber => $some_value, # string city => $some_value, # string companyName => $some_value, # string country => $some_value, # string deviceUniqueIdentifiers => { # SG4InvTypes::ArrayOfString string => $some_value, # string }, emailAddress => $some_value, # string firstName => $some_value, # string lastName => $some_value, # string middleName => $some_value, # string phoneNumber => $some_value, # string postalCode => $some_value, # string realm => $some_value, # string services => { # SG4InvTypes::ArrayOfString string => $some_value, # string }, state => $some_value, # string subscriberID => $some_value, # long }, }, AUTHOR Generated by SOAP::WSDL
In reply to SOAP::WSDL accessing returned data by cannfoddr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |