Gossamer Forum
Home : General : Perl Programming :

SOAP Problems :(

Quote Reply
SOAP Problems :(
Hi,

Got a weird problem with this script :/ It seems to die around here;

Code:
} else {
print "bad " . $response->status_line . "\n";
}

...which gives;

"bad: 500 Internal Server Error"

Code:
#!/usr/local/bin/perl
#
#

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use HTTP::Request;
use XML::Parser;
use DBI;

my $cfg;

$cfg->{script_path} = './';

my $DEBUG = 1;

my $IN = new CGI;
print $IN->header();

my $query = qq|

<APC_Search_Query>
<WebSiteID>177783</WebSiteID>
<PageNumber>1</PageNumber>
<ProductsPerPage>15</ProductsPerPage>
<CategoryID>623</CategoryID>
<SortOrder>R</SortOrder>
<SearchText>Matrix</SearchText>
<inWidth>5</MinWidth>
<MaxWidth>30</MaxWidth>
<MinHeight>10</MinHeight>
<MaxHeight>60</MaxHeight>
<MinPrice></MinPrice>
<MaxPrice>50</MaxPrice>

</APC_Search_Query>
|;

$query =~ s/\n//sig; # only leave newlines in for pretty stuff =)
$query =~ s/\s+//sig; # only leave newlines in for pretty stuff =)

print "Query: $query";

print SoapPosters($query);


sub SoapPosters
{

my $sendxml = shift;
my $result = '';
my $content = qq{
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetProductInformation
xmlns="http://Webservice.Allposters.com/APCF.AffiliateWebService/ProductInformationService">
<APCSearchXml>
<![CDATA[$sendxml]]>
</APCSearchXml>
</GetProductInformation>
</soap:Body>
</soap:Envelope>
};

my $result;
my $ua = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => 'http://webservice.allposters.com/ProductInformationService.asmx');
$request->header(SOAPAction => '"http://webservice.allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation"');
$request->content($content);
$request->content_type("text/xml; charset=utf-8");
my $response = $ua->request($request);
if ($response->is_success) {

my $responeXml = $response->content;
my $xmlp = new XML::Parser(Handlers => {Start => \&StartGetProductInformationResponse,
End => \&EndGetProductInformationResponse,
Char => \&CharGetProductInformationResponse
},
'Non-Expat-Options' => {xmlResult => \$result}
);

eval {$xmlp->parse($responeXml)};

if ($@) {
$result = '';
}

} else {
print "bad " . $response->status_line . "\n";
}
return $result;
}

sub StartGetProductInformationResponse {
my $e = shift;
${$e->{'Non-Expat-Options'}{'xmlResult'}} = '';
my $tag = shift;
if ($tag eq 'GetProductInformationResult') {
$e->{'Non-Expat-Options'}{'GetProductInformationResult'} = 1;
}
}

sub CharGetProductInformationResponse {

my $e = shift;
my $val = shift;
if ($e->{'Non-Expat-Options'}{'GetProductInformationResult'}) {
${$e->{'Non-Expat-Options'}{'xmlResult'}} .= $val;
}

}

sub EndGetProductInformationResponse {

my $e = shift;
my $tag = shift;

if ($tag eq 'GetProductInformationResult') {
$e->{'Non-Expat-Options'}{'GetProductInformationResult'} = 0;
}

}

###########################################################
# Sub for getting the date....
sub date {
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $tz) = localtime();
my @months = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}


1;

Is this a problem my end, or AllPosters?

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SOAP Problems :( In reply to
How about making life easier for yourself? Use a dedicated module.

Code:
use SOAP::Lite;
# use SOAP::Lite +trace => [qw(debug)]; # handy for testing.

...

my @params = (
SOAP::Data->name(WebSiteID => '177783'),
SOAP::Data->name(PageNumber => '1'),
...
);

my $soapposters = SOAP::Lite->new(
uri => "http://webservice.allposters.com/ProductInformationService.asmx",
endpoint => "http://webservice.allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation",
# proxy => "",
autotype => 0,
);


$soapposters->call('GetProductInformation' => @params);

my $result = $soapposters->call->result;

# easiest way to get info back is to feed them into a new CGI key/value pair.

my $soap = CGI->new($result);

my $isvalid = $soap->param('valid');

if ($isvalid eq "true") {

# valid
}

else {

# not valid. we should have access to any error values, too.

my $code = $s->param('code');

}

- wil
Quote Reply
Re: [Wil] SOAP Problems :( In reply to
Hi,

Thanks .. I never managed to figure that module out... but your sample helped Smile

I'm kinda getting there. I've changed it a bit, to suit the test script I'm running it in;

Code:
#################

my $IN = new CGI;
print $IN->header();

my $catID = $IN->param('cid') || 0; # define the category ID passed in...



#use SOAP::Lite;
use SOAP::Lite +trace => [qw(debug)]; # handy for testing.

my @params = (
SOAP::Data->name(WebSiteID => '177783'),
SOAP::Data->name(PageNumber => '1'),
SOAP::Data->name(CategoryID => '623'),
);

my $soapposters = SOAP::Lite->new(
uri => "http://webservice.allposters.com/ProductInformationService.asmx",
endpoint => "http://webservice.allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation",
# proxy => "",
autotype => 0,
);


$soapposters->call('GetProductInformation' => @params);

my $result = $soapposters->call->result;

# easiest way to get info back is to feed them into a new CGI key/value pair.

my $soap = CGI->new($result);

my $isvalid = $soap->param('valid');

if ($isvalid eq "true") {

print "WAHOO!" . Dumper($soap);

}

else {


my $code = $soap->param('code');
print "Ack, error! $code";
exit;

}

However, this gives me an error;

Quote:
Content-type: text/html
Software error:
Transport is not specified (using proxy() method or service description)

For help, please send mail to the webmaster ([no address given]), giving this error message and the time and date of the error.

Any ideas? Angelic

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SOAP Problems :( In reply to
I think this problem is solved by setting your proxy the same as your service, i.e.:

Code:
endpoint => "http://webservice.allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation",
proxy => "http://webservice.allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation",

- wil
Quote Reply
Re: [Wil] SOAP Problems :( In reply to
Hi,

Thanks,... that kinda worked <G>

It now gives;

Code:
405 Method not allowed at index.cgi line 53

Line 53 is the first part of the following code;

Code:
my $soapposters = SOAP::Lite->new(
uri => "http://webservice.allposters.com/ProductInformationService.asmx",
endpoint => "http://webservice.allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation",
proxy => "http://webservice.allposters.com/APCF.AffiliateWebService/ProductInformationService/GetProductInformation",
autotype => 0,
);

Afraid I'm still a bit of a newb with this SOAP stuff :(

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SOAP Problems :( In reply to
That's a HTTP error message. Does the server allow you to post things as well as retrieve data?

- wil
Quote Reply
Re: [Wil] SOAP Problems :( In reply to
Hi,

Yeah, it should do :/

The sample code from my first post, was taken directly from an example script. Even that doesn't work :| Maybe something my end?

I've emailed AllPosters support, to see if they can shed any light.

There are tons of people using their SOAP request method, so it would be pretty silly if it was something their end Unsure

Thanks for the reply though :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] SOAP Problems :( In reply to
Well, that's definitily an error message returned from their server.

- wil