LoginSignup
4
6

More than 3 years have passed since last update.

Blue Prism のプロセスを Python を使って実行する(SOAP)

Last updated at Posted at 2020-01-10

はじめに

Blue Prism では、プロセス(ロボット)を WebService として公開し、外部から実行することができます。
この記事では、Python でクライアントを書いて、Blue Prism のプロセスを呼び出してみます。

WebService として公開したプロセスを実行するためには、2つの前提条件があります。別記事を参照して前提条件を整えておきましょう。

  • A. Blue Prism のサーバーサービスが起動していること
  • B. public スイッチで起動したランタイムリソースがあること

プロセスを WebService として公開する

インタラクティブクライアントで、"システム" タブを開き、"プロセス > 公開" を選択します。画面右側に表示される "プロセスを公開" をクリックします。
publish_process_00.jpg

WebService として公開したいプロセス(ここでは "logSample")を選択し、"次へ" ボタンをクリックします。
publish_process_01.jpg

"プロセスの公開名" を確認し、"完了" ボタンをクリックします。
publish_process_02.jpg

実際の運用を考えると、長いプロセスの本体と、処理の受付だけを行うプロセスを分割しておいて、WebService クライアントには同期的にレスポンスを返すような作りにしておく必要がありそうです。

Python でクライアントを作成する

WSDL をダウンロードしておきます。

公開したプロセスの WSDL は、ランタイムリソース が公開しています(サーバーが WSDL を返すようなAPIは用意されていません。不思議ですね。。)。今回はランタイムリソースをポート8183で公開しているので、 http://127.0.0.1:8183/ws/ をブラウザで開きます。すると、下記のように WebService として公開されたプロセスの一覧が表示されます。
webservice_list.jpg

今回は、このページから WSDL ファイルをダウンロードして使用します。 Python スクリプトを開発するディレクトリに、logSample.xml という名前で保存しておきます。

必要な Python モジュール をインストールする

Pipenv で Pythonスクリプトの開発環境を準備します。

% pipenv --python 3.7
Creating a virtualenv for this project…
Pipfile: /Users/m-nakamura/Documents/blueprism-process-invoker_/Pipfile
Using /Users/m-nakamura/.pyenv/versions/3.7.4/bin/python3 (3.7.4) to create virtualenv…
⠹ Creating virtual environment...Using base prefix '/Users/m-nakamura/.pyenv/versions/3.7.4'
New python executable in /Users/m-nakamura/.local/share/virtualenvs/blueprism-process-invoker_-30X4pztG/bin/python3
Also creating executable in /Users/m-nakamura/.local/share/virtualenvs/blueprism-process-invoker_-30X4pztG/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /Users/m-nakamura/.pyenv/versions/3.7.4/bin/python3

✔ Successfully created virtual environment!
Virtualenv location: /Users/m-nakamura/.local/share/virtualenvs/blueprism-process-invoker_-30X4pztG
Creating a Pipfile for this project…

必要なライブラリをインストールします。Python で SOAPを使うには、Zeep がおすすめのようなので、こちらを利用します。
Zeep、便利ですね!

% pipenv install zeep
Installing zeep…
Adding zeep to Pipfile's [packages]…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (663ec6)!
Installing dependencies from Pipfile.lock (663ec6)…
    ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 15/15 — 00:00:03
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

Zeep の機能に、WSDLの内容を調べる機能 があります。試してみると、プロセスの入力パラメーターと出力パラメーターが、 xsd:string 型になっていることがわかります。

% pipenv run python -m zeep logSample.xml 

Prefixes:
     xsd: http://www.w3.org/2001/XMLSchema
     ns0: urn:blueprism:webservice:logsample

Global elements:


Global types:
     xsd:anyType
     xsd:ENTITIES
     xsd:ENTITY
     xsd:ID
     xsd:IDREF
     xsd:IDREFS
     xsd:NCName
     xsd:NMTOKEN
     xsd:NMTOKENS
     xsd:NOTATION
     xsd:Name
     xsd:QName
     xsd:anySimpleType
     xsd:anyURI
     xsd:base64Binary
     xsd:boolean
     xsd:byte
     xsd:date
     xsd:dateTime
     xsd:decimal
     xsd:double
     xsd:duration
     xsd:float
     xsd:gDay
     xsd:gMonth
     xsd:gMonthDay
     xsd:gYear
     xsd:gYearMonth
     xsd:hexBinary
     xsd:int
     xsd:integer
     xsd:language
     xsd:long
     xsd:negativeInteger
     xsd:nonNegativeInteger
     xsd:nonPositiveInteger
     xsd:normalizedString
     xsd:positiveInteger
     xsd:short
     xsd:string
     xsd:time
     xsd:token
     xsd:unsignedByte
     xsd:unsignedInt
     xsd:unsignedLong
     xsd:unsignedShort

Bindings:
     Soap11Binding: {urn:blueprism:webservice:logsample}logSampleSoapBinding

Service: logSampleService
     Port: logSampleSoap (Soap11Binding: {urn:blueprism:webservice:logsample}logSampleSoapBinding)
         Operations:
            logSample(message: xsd:string) -> outmessage: xsd:string

logsample.xml という名前で WSDL ファイルを保存した同じディレクトリに、logsample.py という名前で Python スクリプトを作成します。

from pathlib import Path
from zeep import Client

from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport

# Blue Prism の認証情報を設定します
session = Session()
session.auth = HTTPBasicAuth('admin', 'admin_password_xxxxxx')

# 同じディレクトリに保存した WSDL ファイルのパスを取得します
wsdl = Path.cwd() / "logSample.xml"
client = Client(str(wsdl), transport=Transport(session=session))
service = client.service

# logSampleサービスの入力パラメーターを名前付き引数で指定します
res = service.logSample(message="hogehoge")

# 単一の文字列型出力パラメータは、レスポンスとして直接返されます
print(type(res))
print(res)

プロセスを実行する

先ほど作成した logSample.py が保存されているディレクトリで、スクリプトを実行します。プロセスの出力パラメーターが出力され、プロセスが実行されたことが確認できます。

% pipenv run python logSample.py
<class 'str'>
exec at 04/01/20 23:25:12hogehoge

インタラクティブクライアントからも実行されたことが確認できます。"コントロール" タブを開き、"セッション管理 > 今日" を開きます。
process_results.jpg

問題点

機能を試してみて、下記点が気になりました。

  • ランタイムリソースが WebService のエンドポイントになっている。ランタイムリソースはエフェメラルなものという位置付けなので、エンドポイントの場所がコロコロ変わる可能性がある。利用する側からすると、安定して利用できないという問題が生じるのでは?
    • サーバー側に WebService のエンドポイントがあった方が良いのではないか? なぜそのようなデザインになっているのか、理由があるのかもしれない。。。
    • 次善の策として、ランタイムリソースの一覧を引くためのAPIがあれば良いかな、とも思ったが、それも無さそう。
    • 「ヘルプ - Blue PrismリソースPCコマンド」に、"pool", "members", "availability", "proclist" のようなコマンドがあるが、ランタイムリソース全体を把握するための手段は無さそう。
    • Automate.exe の起動オプションに、バインドするIPアドレスを指定するものが無い。
  • ライセンス不足などで、プロセスを起動するセッションの作成に失敗した場合、WebServiceクライアント側でリトライの作り込みが必要になってしまう。ワークキューにセッションを使用することなくエンキューできるAPIがほしい。。。
4
6
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6