SOAP 请求

SOAP 是一种协议,用于促进通过因特网的远程调用,允许两个程序进行通信。

命令可用性: 本地 IBM RPA SaaS 和 IBM RPA

描述

SOAP(简单对象访问协议)是一种从发送应用程序到接收应用程序共享信息的方式,通常使用 HTTP 会话。 信息共享采用 XML( eXtensible Markup Language)格式传输。 您可以根据自己的需要发送 SOAP 请求,只需填写以下字段即可: URL、操作、来源等字段。 在此之后,接收请求的应用程序将返回与所做请求相关的内容。

重要信息:使用服务的 API 文档可帮助您了解 API 行为并遵循其指示信息来发出请求。

限制

如果使用 Map XML (mapXml) 命令来获取请求的内容,那么此命令可能无法正常工作。

脚本语法

IBM RPA 的专有脚本语言的语法与其他编程语言类似。 该脚本语法在脚本文件中定义命令的语法。 您可以在 IBM RPA Studio的 "脚本" 方式下使用此语法。

soapRequest --url(String) [--headers(StringDictionary<String>)] [--username(String)] [--password(String)] --action(String) --source(String) [--noproxy(Boolean)] [--timeout(TimeSpan)] (Boolean)=success (String)=value (Numeric)=statusCode (String)=reasonPhrase (StringDictionary<String>)=headers (StringDictionary<String>)=contentHeaders

输入参数

下表显示了此命令中提供的输入参数的列表。 在表中,您可以看到在 IBM RPA Studio的脚本方式及其 Designer 方式等效标签中工作时的参数名称。

设计器方式标签 脚本方式名称 必需的 接受的变量类型 描述
URL url Required Text 目标服务器的地址。
headers headers Optional String Dictionary<Text> 例如,头调用有关请求的头 (例如,主机或 cookie) 的信息。
用户名 username Optional Text 网络凭证用户。 用于代理认证的参数。
密码 password Optional Text 网络凭证密码。 用于代理认证的参数。
操作 action Required Text 要在请求中运行的操作。 更多信息,请参阅 SOAPAction HTTP 头字段 🡥。
source Required Text 请求的 SOAP 内容。
忽略全局代理配置 noproxy Optional Boolean 启用以忽略 IBM RPA 安装或 IBM RPA Client: Proxy 🡥 页面中的代理集。
Timeout timeout Optional Time Span, Number, Text 最长响应时间。 缺省时间为 5 秒。

输出参数

Designer 方式 脚本方式 接受的变量类型 描述
成功 success Boolean 如果成功发送请求,那么返回 True,否则返回 False
响应 value Text 返回从服务器到本地计算机的 SOAP 响应内容。
状态代码 statusCode Number 返回 HTTP 状态代码,说明 SOAP 请求的处理情况。 有关更多详细信息,请参阅 statusCode 参数选项
原因阐述 reasonPhrase Text 由服务器发送的带有状态码的阐述。 状态码对应于显示发生的错误类型的三位数; 原因句是对此错误的含义的简短描述。
headers headers String Dictionary<Text> 返回响应头,其中包含与申请相关的信息。
消息头 contentHeaders String Dictionary<Text> 返回 SOAP 内容头,如 RFC 2616 🡥中所定义。

statusCode 参数选项

服务器解释 HTTP 请求,并向客户端发送响应。 此响应包含用于指示状态请求的代码,其中第一个数字指示响应的类。

在下表中,您可以找到响应代码及其描述。 请参阅 状态码 🡥 以获取详细信息。

响应代码 描述
1xx 信息响应。
2xx 成功响应。
3xx 重定向消息。
4xx 请求错误。
5xx 服务器上存在错误。

示例

此命令发送 SOAP 类型的消息协议以获取有关国家或地区的信息,例如其标志, Iso 代码,首都等。

defVar --name soapRequestSent --type Boolean
defVar --name soapResponseBody --type String
defVar --name soapResponseStatusCode --type Numeric
defVar --name countryIsoCode --type String
defVar --name countryName --type String
defVar --name countryCapitalCity --type String
defVar --name countryPhoneCode --type String
defVar --name countryContinentalCode --type String
defVar --name countryCurrencyIsoCode --type String
defVar --name countryFlagUrl --type String
defVar --name countryLanguages --type String
defVar --name sCountryISOCodeToSendOnSoapRequest --type String --value BR
defVar --name target_URL --type String --value "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso"
defVar --name SOAP_ACTION --type String --value "http://www.oorsprong.org/websamples.countryinfo/CountryInfoServiceSoapType/FullCountryInfoRequest"
defVar --name languageNodesCount --type Numeric
defVar --name REGEX_LANGUAGE_NODES --type String --value "\\<m\\:tLanguage\\>(.+?)\\<\\/m\\:tLanguage\\>"
defVar --name REGEX_SISOCODE_NODES --type String --value "\\<m\\:sISOCode\\>(.+?)\\<\\/m\\:sISOCode\\>"
defVar --name occurenceNumber --type Numeric
defVar --name REGEX_LANGUAGES_NODES --type String --value "\\<m\\:Languages\\>(.+?)\\<\\/m\\:Languages\\>"
defVar --name languagesNodes --type String
defVar --name languageNode --type String
defVar --name languageIsoCode --type String
defVar --name countryLanguageIsoCodes --type List --innertype String
defVar --name REGEX_NAME_NODES --type String --value "\\<m\\:sName\\>(.+?)\\<\\/m\\:sName\\>"
defVar --name REGEX_CAPITALCITY_NODES --type String --value "\\<m\\:sCapitalCity\\>(.+?)\\<\\/m\\:sCapitalCity\\>"
defVar --name REGEX_COUNTRYFLAG_NODES --type String --value "\\<m\\:sCountryFlag\\>(.+?)\\<\\/m\\:sCountryFlag\\>"
soapRequest --url "${target_URL}" --action "${SOAP_ACTION}" --source "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://www.oorsprong.org/websamples.countryinfo\">\r\n   <soapenv:Header/>\r\n   <soapenv:Body>\r\n      <web:FullCountryInfo>\r\n         <web:sCountryISOCode>${sCountryISOCodeToSendOnSoapRequest}</web:sCountryISOCode>\r\n      </web:FullCountryInfo>\r\n   </soapenv:Body>\r\n</soapenv:Envelope>" soapRequestSent=success soapResponseBody=value soapResponseStatusCode=statusCode
logMessage --message "soapResponseStatusCode=${soapResponseStatusCode}\r\nsoapResponseBody=${soapResponseBody}" --type "Info"
mapXml --xml "${soapResponseBody}" --mappings "{\"//*[local-name()=\'sISOCode\']\":\"${countryIsoCode}\",\"//*[local-name()=\'sName\']\":\"${countryName}\",\"//*[local-name()=\'sCapitalCity\']\":\"${countryCapitalCity}\",\"//*[local-name()=\'sPhoneCode\']\":\"${countryPhoneCode}\",\"//*[local-name()=\'sContinentCode\']\":\"${countryContinentalCode}\",\"//*[local-name()=\'sCurrencyISOCode\']\":\"${countryCurrencyIsoCode}\",\"//*[local-name()=\'sCountryFlag\']\":\"${countryFlagUrl}\",\"//*[local-name()=\'Languages\']\":\"${countryLanguages}\"}"
//Notice that there are some limitations here. Either  mapXml returns more than one node or it can't return the node. To work around these limitations, you need to use RegEx.
//Known limitations:
//    (1) If XML has namespaces and nodes with the same name, you can't select an specific node. Must use regex to get specific node.
//    (2) If XML has namespaces and nodes with children nodes, you can't get all children by targeting parent. Must use regex to parse.
logMessage --message "countryIsoCode=${countryIsoCode}\ncountryName=${countryName}\ncountryCapitalCity=${countryCapitalCity}\ncountryLanguageIsoCodes=${countryLanguages}\r\ncountryFlagUrl=${countryFlagUrl}" --type "Info"
//These next two regexes are straightforward. Since we know the response's structure, we can get the strings directly.
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_SISOCODE_NODES}" --regexOptions "0" --groupnumber 1 countryIsoCode=value
logMessage --message "countryIsoCode=${countryIsoCode}" --type "Info"
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_NAME_NODES}" --regexOptions "0" --groupnumber 1 countryName=value
logMessage --message "countryName=${countryName}" --type "Info"
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_CAPITALCITY_NODES}" --regexOptions "Singleline" --groupnumber 1 countryCapitalCity=value
logMessage --message "countryCapitalCity=${countryCapitalCity}" --type "Info"
//A comes the magic: a node that can have multiple child nodes. To parse such node, you must count its children, get them, and then loop through all of them.
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_LANGUAGES_NODES}" --regexOptions "Singleline" --groupnumber 1 languagesNodes=value
countTextOccurrences --text "${languagesNodes}" --useRegex  --regexPattern "${REGEX_LANGUAGE_NODES}" --regexOptions "Singleline" --startindex 1 languageNodesCount=value
for --variable ${occurenceNumber} --from 1 --to ${languageNodesCount} --step 1
	getRegex --text "${languagesNodes}" --regexPattern "${REGEX_LANGUAGE_NODES}" --regexOptions "Singleline" --groupnumber 1 --getbyindex  --occurrenceindex ${occurenceNumber} languageNode=value
	getRegex --text "${languageNode}" --regexPattern "${REGEX_SISOCODE_NODES}" --regexOptions "0" --groupnumber 1 languageIsoCode=value
	add --collection "${countryLanguageIsoCodes}" --value "${languageIsoCode}"
next
logMessage --message "countryLanguageIsoCodes=${countryLanguageIsoCodes}" --type "Info"
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_COUNTRYFLAG_NODES}" --regexOptions "Singleline" --groupnumber 1 countryFlagUrl=value
logMessage --message "countryFlagURL=${countryFlagUrl}" --type "Info"
webStart --name browser --type "Chrome"
webNavigate --url "${countryFlagUrl}"
webClose --name browser --leavebrowseropen