This is a simple Perl program to query business info thru SOAP.

To use it, just type the business name, such as "IBM", and return. To quit, just type return without business name.

use Socket; use IO::Select; use XML::Simple; use Data::Dumper; use strict; use warnings; while (1) { print "Business: "; my $business = <>; chomp($business); if ($business) { my $businesses = find($business); display($businesses); } else { last; } } sub display { my $businesses = shift; foreach my $key (keys(%$businesses)) { print "-$key\n"; print "---$businesses->{$key}\n" if(defined($businesses->{$key +})); } print "=========================================\n"; } sub find { my $name = shift; socket(UDDI, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die " +socket: $!"; connect(UDDI, sockaddr_in(80, inet_aton("www-3.ibm.com"))) || die +"connect: $!"; my $envelope = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.or +g/soap/envelope/\">" . "<SOAP-ENV:Body>" . "<find_business generic=\"2.0\" maxRows=\"100\" xmlns= +\"urn:uddi-org:api_v2\">" . "<name>" . $name . "</name>" . "</find_business>" . "</SOAP-ENV:Body>" . "</SOAP-ENV:Envelope>"; my $msg = "POST /services/uddi/inquiryapi HTTP/1.1\r\n" . "Content-Type: text/xml; charset=\"utf-8\"\r\n" . "Content-Length: " . length($envelope) . "\r\n" . "SOAPAction: \"\"\r\n" . "Cache-Control: no-cache\r\n" . "Pragma: no-cache\r\n" . "User-Agent: Peter Script\r\n" . "Host: www-3.ibm.com\r\n" . "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n" + . "Connection: keep-alive\r\n" . "\r\n" . $envelope; syswrite(UDDI, $msg); my $res = ""; my $sel = new IO::Select(*UDDI); while ($sel->can_read) { my $chunk; sysread(UDDI, $chunk, 100000); if (!length($chunk)) { last; } else { $res .= $chunk; } } close(UDDI); $res =~ m/.*?\r\n\r\n(.*)/; $res = $1; my $hash = XMLin($res); my $result = {}; foreach my $business (@{$hash->{"SOAP:Body"}->{"businessList"}->{" +businessInfos"}->{"businessInfo"}}) { $result->{$business->{"name"}->{"content"}} = $business->{"des +cription"}->{"content"}; } return $result; }

Replies are listed 'Best First'.
Re: UDDI busness query
by zentara (Cardinal) on Jan 09, 2004 at 15:51 UTC
    I get an error. If I type in 'Walmart', I get back a couple of separator lines, and a prompt for a new business. If I enter IBM, I get:
    Not an ARRAY reference at ./UDDI-business-query line 77, <> line 2.

      Let's look at the IBM problem.

      IBM was one of the business I tested, and it worked. Actually one of the business came back under IBM was IBM Japan, and I got some wide charatcters.

      I cannot cut and paste my testing result now, as I am behind firewall, but I definitely will update this post tonight. (I can enhance the code to work with firewall, but ...)

      My guess is that, when you only got one business back in the SOAP reply, XML::Simple does not parse it into an array ref, as it does when multiple business were sent back, and I missed that. So I probably should do a ref() first.

      However you should get the same SOAP reply as I did, when we both enquery IBM. This puzzles me a lot.

      Here is the updated code, but the enhancement is untested, which I do tonight back home.

      use Socket; use IO::Select; use XML::Simple; use Data::Dumper; use strict; use warnings; while (1) { print "Business: "; my $business = <>; chomp($business); if ($business) { my $businesses = find($business); display($businesses); } else { last; } } sub display { my $businesses = shift; foreach my $key (keys(%$businesses)) { print "-$key\n"; print "---$businesses->{$key}\n" if(defined($businesses->{$key +})); } print "=========================================\n"; } sub find { my $name = shift; socket(UDDI, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die " +socket: $!"; connect(UDDI, sockaddr_in(80, inet_aton("www-3.ibm.com"))) || die +"connect: $!"; my $envelope = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.or +g/soap/envelope/\">" . "<SOAP-ENV:Body>" . "<find_business generic=\"2.0\" maxRows=\"100\" xmlns= +\"urn:uddi-org:api_v2\">" . "<name>" . $name . "</name>" . "</find_business>" . "</SOAP-ENV:Body>" . "</SOAP-ENV:Envelope>"; my $msg = "POST /services/uddi/inquiryapi HTTP/1.1\r\n" . "Content-Type: text/xml; charset=\"utf-8\"\r\n" . "Content-Length: " . length($envelope) . "\r\n" . "SOAPAction: \"\"\r\n" . "Cache-Control: no-cache\r\n" . "Pragma: no-cache\r\n" . "User-Agent: Peter Script\r\n" . "Host: www-3.ibm.com\r\n" . "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n" + . "Connection: keep-alive\r\n" . "\r\n" . $envelope; syswrite(UDDI, $msg); my $res = ""; my $sel = new IO::Select(*UDDI); while ($sel->can_read) { my $chunk; sysread(UDDI, $chunk, 100000); if (!length($chunk)) { last; } else { $res .= $chunk; } } close(UDDI); $res =~ m/.*?\r\n\r\n(.*)/; $res = $1; my $hash = XMLin($res); my $result = {}; if (ref($hash->{"SOAP:Body"}->{"businessList"}->{"businessInfos"}- +>{"businessInfo"}) eq "ARRAY") { foreach my $business (@{$hash->{"SOAP:Body"}->{"businessList"} +->{"businessInfos"}->{"businessInfo"}}) { $result->{$business->{"name"}->{"content"}} = $business->{ +"description"}->{"content"}; } } else { #I will add later, as I cannot test now, and I don't want to p +ost untested code in this case } return $result; }
Re: UDDI business query
by Vautrin (Hermit) on Jan 22, 2004 at 00:49 UTC

    Is there a reason you are opening your own sockets instead of using a CPAN module? Your code looks cool but it's hard to figure out what is going on because you're mixing implementation of SOAP queries with the query itself.

    Am I correct that you are querying ibm.com for all of your responses? Does IBM offer this as a service?

    -Dan