機械翻訳について

Perl

HTTP::RequestSOAP::Liteなどの様々な手法を使用してWebサービスを呼び出すには、Perlを使用します。

HTTP::Request

SOAP Webサービス用にXMLを直接作成し、処理するには、HTTP::Requestを使用します。

次に示すサンプル・コードは、次を実行します。
  1. サービスを呼び出すxmlペイロードを作成します。 このコード例は、ハードコードされた文字列(UTF-8バイト配列にエンコード)を要求に渡します。

  2. サービス・コールの資格証明のため、Base 64でエンコードされた文字列を作成します。

  3. サービスのPOST要求を作成します。

  4. Base64でエンコードされた資格証明を使用して基本認証を使用するため、要求コンテンツ・タイプをxmlとして構成します。

  5. 呼び出すSOAPActionを設定します。 サービス・コールはこの値がなくても行えますが、これが推奨される標準です。

  6. xmlペイロードを要求に書き込みます。

  7. サービスを呼び出します。

  8. 応答を処理します。 この例は、応答を単に出力します。

#!/usr/bin/perl -w

use strict;

use LWP::UserAgent;
use HTTP::Request::Common;
use MIME::Base64;

my $ua = LWP::UserAgent->new(agent => 'perl post');

# Construct xml payload to invoke the service. In the example, it is hard coded.
my $envelope = <<END;
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <findRule
               xmlns="http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/types/">
    <findCriteria>
        <fetchStart xmlns="http://xmlns.oracle.com/adf/svc/types/">0</fetchStart>
        <fetchSize xmlns="http://xmlns.oracle.com/adf/svc/types/">-1</fetchSize>
        <filter xmlns="http://xmlns.oracle.com/adf/svc/types/">
     <group>
        <upperCaseCompare>false</upperCaseCompare>
        <item>
          <upperCaseCompare>false</upperCaseCompare>
          <attribute>RuleId</attribute>
          <operator>=</operator>
          <value>300000000851162</value>
        </item>
     </group>
    </filter>
     <excludeAttribute xmlns="http://xmlns.oracle.com/adf/svc/types/">false</excludeAttribute>
    </findCriteria>
    <findControl>
       <retrieveAllTranslations xmlns="http://xmlns.oracle.com/adf/svc/types/">false</retrieveAllTranslations>
    </findControl>
    </findRule>
  </soap:Body>
</soap:Envelope>
END

# Construct the base 64 encoded string used as the credentials for the service call.
my $credentials = encode_base64('username:password');
my $url = 'https://host:port/icCnSetupCreditRulesPublicService/CreditRuleService';

# Create new POST request
my $req=new HTTP::Request 'POST',$url;

# Configure the request to use basic authentication, with base64-encoded user name and password to invoke the service.
$req->header('Authorization' => "Basic " . $credentials);

# Set the SOAP action to be invoked; while the call works without this, the value is expected to be set based on standards
$req->header('SOAPAction' =>
'http://xmlns.oracle.com/apps/incentiveCompensation/cn/creditSetup/creditRule/creditRuleService/findRule');

# Configure the request content type to be xml, HTTP method to be POST, and set the content length
$req->header('Content-Type' => 'text/xml;charset=UTF-8');

# Write the xml payload to the request.
$req->content($envelope);

# Call the service
my $response=$ua->request($req);

# Process the response. In this example, we simply print the response.
print $response->error_as_HTML unless $response->is_success;
print $response->as_string;

SOAP::Lite

以下は、次を実行するためのSOAP:Liteコード例です。
  1. 新しいSOAP Liteを作成します。

  2. エンベロープの名前空間を登録します。

  3. セキュリティ情報を使用してSOAPヘッダーを作成します。

  4. サービスを呼び出します。

  5. 応答を処理します。 この例は、応答を単に出力します。

#!/usr/bin/perl
use lib '/usr/lib/perl5/5.8.8/';
use MIME::Base64;
use SOAP::Lite;

SOAP::Lite->import(trace => debug);

# Create a new instance for the SOAP Lite
my $soap = SOAP::Lite->new(
           proxy => 'http://host:port/hcmEmploymentCoreWorker/WorkerService',
           service => 'http://host:port/hcmEmploymentCoreWorker/WorkerService?wsdl',
           );
		   
# Register namespace(s) for the envelope
my $serializer = $soap->serializer();
$serializer->register_ns( 'http://xmlns.oracle.com/apps/hcm/employment/core/workerService/types/', 'typ' );

# Create SOAP header with security information
my $auth = SOAP::Header->new( name => "wsse:Security" );
$auth->attr( { "xmlns:wsse" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecuritysecext-1.0.xsd"});
$auth->mustUnderstand(1);
$auth->value( \SOAP::Data->value(
               SOAP::Data->name("wsse:UsernameToken" => \SOAP::Data->value(
                  SOAP::Data->name("wsse:Username" => 'username')->type(""),
                  SOAP::Data->name("wsse:Password" => 'password')->type("")
                  ->attr( {"Type" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-usernametoken-profile-1.0#PasswordText"}),
                  SOAP::Data->name("wsse:nonce" => 'jwCzGGijT90Wml6eZe4cxg==')->type("")
                  ->attr( {"EncodingType" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsssoap-message-security-1.0#Base64Binary"}),
                  SOAP::Data->name("wsse:created" => '2012-07-04T06:49:48.981Z')->type("")
                  )->type("")
                )->attr( {"wsu:Id" => "UsernameToken-2",
                          "xmlns:wsu" => "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-utility-1.0.xsd"
                         })
                )->type("")
            );
			
# Populate parameters to call the service
my $parameters =SOAP::Data->name("typ:personId" => '300000010363707')->type("");

# Call the service
my $result = $soap->call(SOAP::Data->name('typ:getWorker') => $parameters, $auth);

# Process the response. In this example, we simply print the response
die $result->faultstring if ($result->fault);
print $result->result, "\n";
関連トピック
  • Javaクライアント
  • Oracle Database
  • .NET Framework
  • PHP
  • Python
  • Ruby
  • SOAP Webサービスの呼出し