Blue Prism exposes processes (robots) as WebServices and can be executed externally. In this article, I'll write a client in Python and call a Blue Prism process.
There are two prerequisites for running a process exposed as a WebService. [Separate article](https://qiita.com/muuuuuwa/items/8fdd65eb0e0b71263644#blue-prism-%E3%81%AE%E3%82%B5%E3%83%BC%E3%83%90%E3% 83% BC% E3% 82% B5% E3% 83% BC% E3% 83% 93% E3% 82% B9% E3% 82% 92% E8% B5% B7% E5% 8B% 95% E3% 81% Let's set the prerequisites by referring to 99% E3% 82% 8B).
- A. The Blue Prism server service is running
- B. There are runtime resources started on the public switch
In the interactive client, open the "System" tab and select "Process> Publish". Click "Publish Process" displayed on the right side of the screen.
Select the process you want to publish as a WebService (here "logSample") and click the "Next" button.
Confirm the "Public name of the process" and click the "Finish" button.
Considering the actual operation, it seems necessary to separate the main body of the long process and the process that only accepts the process, and make it so that the response is returned synchronously to the WebService client.
The WSDL of the published process is published by ** Runtime Resources ** (there is no API for the server to return a WSDL, isn't it?). This time we are exposing the runtime resources on port 8183, so open http://127.0.0.1:8183/ws/
in your browser. Then, a list of processes published as WebService will be displayed as shown below.
This time, download and use the WSDL file from this page. Save it as `` `logSample.xml``` in the directory where you develop your Python script.
Prepare the Python script development environment with Pipenv.
% 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…
Install the required libraries. To use SOAP with Python, Zeep seems to be recommended, so I will use it. Zepp is convenient!
% 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.
One of Zepp's features is the ability to look up the contents of a WSDL (https://python-zeep.readthedocs.io/en/master/index.html#getting-started). If you try, you will see that the input and output parameters of the process are of type 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
Create a Python script with the name `` `logsample.py``` in the same directory where you saved the WSDL file with the name logsample.xml.
from pathlib import Path
from zeep import Client
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep.transports import Transport
# Set Blue Prism credentials
session = Session()
session.auth = HTTPBasicAuth('admin', 'admin_password_xxxxxx')
# Get the path of the WSDL file saved in the same directory
wsdl = Path.cwd() / "logSample.xml"
client = Client(str(wsdl), transport=Transport(session=session))
service = client.service
# Specify the input parameters of the logSample service with named arguments
res = service.logSample(message="hogehoge")
# A single string output parameter is returned directly as a response
print(type(res))
print(res)
Run the script in the directory where the `` `logSample.py``` you created earlier is stored. The output parameters of the process are output, and you can confirm that the process has been executed.
% pipenv run python logSample.py
<class 'str'>
exec at 04/01/20 23:25:12hogehoge
You can also see that it was executed from the interactive client. Open the "Controls" tab and open "Session Management> Today".
After trying the function, I was concerned about the following points.
Recommended Posts