Das folgende Beispiel zeigt, wie Sie mit einem PERL-Skript eine Verbindung zum CA Business Service Insight-Bericht Webservice herstellen und die XML-Kriterienparameter mit einem HTTP-Stream in einen SOAP-Envelope übertragen.
Hinweis: Der XML-Code, der in den SOAP-Envelope übertragen wird, darf nicht die Symbole "<" oder ">" enthalten, sondern nur ihren HTML-Code (d. h. <=> >=<)
#!/usr/bin/perl
#use strikt;
use LWP::UserAgent;
use HTTP::Request::Common;
use XML::Simple;
use Data::Dumper;
my $userAgent = LWP::UserAgent > new(agent => 'Mozilla/5.0');
### Creating a Oblicore Session Kontext - Oblicore Session ID is stored in $scid ###
my $message = "<?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>
<CreateSessionContext xmlns=\"http://www.oblicore.com\">
<userName>sadmin</userName>
<organizationName>Oblicore</organizationName>
</CreateSessionContext>
</soap:Body>
</soap:Envelope>";
my $response = $userAgent > request(POST 'http://obonob/WebServices/OblicoreAuth.asmx',Content_type => 'text/xml', Content => $message);
print $response > error_as_HTML unless $response > is_success;
my $result = $response > as_string;
my $xmlstart = index $result, "<?xml";
my $xmlend = length $result;
my $xmltext = substr $result, $xmlstart, ($xmlend - $xmlstart);
my $xml = new XML::Simple;
my $data = $xml > XMLin($xmltext);
my $scid = ($data > {'soap:Body'} > {'CreateSessionContextResponse'} > {'CreateSessionContextResult'});
print "Session ID : ".$scid."\n";
### Try to get contract list from Oblicore ###
my $criteria_xml = "<Criteria><Name>a*</Name><Status>EFFECTIVE</Status></Criteria>";
print "<?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>
<GetContractsAdvanced xmlns=\"http://www.oblicore.com\">
<sessionID>".$scid."</sessionID>
<criteriaXML>".$criteria_xml."</criteriaXML>
</GetContractsAdvanced>
</soap:Body>
</soap:Envelope>";
my $message = "<?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>
<GetContractsAdvanced xmlns=\"http://www.oblicore.com\">
<sessionID>".$scid."</sessionID>
<criteriaXML>".$criteria_xml."</criteriaXML>
</GetContractsAdvanced>
</soap:Body>
</soap:Envelope>";
#my $message = "<?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>
# <GetContracts xmlns=\"http://www.oblicore.com\">
# <sessionID>".$scid."</sessionID>
# </GetContracts>
# </soap:Body>
#</soap:Envelope>";
### is_well_formed($message)
print $message;
my $response = $userAgent > request(POST 'http://obonob/WebServices/Contracts.asmx', Content_Type => 'text/xml', Content => $message);
print $response > error_as_HTML unless $response > is_success;
my $result = $response > as_string;
print Dumper($result); # Output of contract list
### Close the Oblicore Session ###
my $message = "<?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>
<ClearSessionContext xmlns=\"http://www.oblicore.com\">
<sessionContextID>".$scid."</sessionContextID>
</ClearSessionContext>
</soap:Body>
</soap:Envelope>";
my $response = $userAgent > request(POST 'http://obonob/WebServices/OblicoreAuth.asmx', Content_Type => 'text/xml', Content => $message);
print $response > error_as_HTML unless $response > is_success;
|
Copyright © 2013 CA.
Alle Rechte vorbehalten.
|
|