Workflow Manager 1.0 Http 活动
Workflow Manager 1.0 提供一组消息活动用于向 Http 服务发送出站消息。一般而言,每个活动代表一个 Http 谓词。本主题概述了这些活动。
本主题内容
Http 活动通用属性
Http 活动
指定请求和响应的内容
DynamicValue 中的 Http 标头
Http 活动通用属性
Http 活动的参数非常类似,但根据活动封装的特定 Http 操作的相关内容而有所不同。每个活动的参数允许指定核心参数集,需要设置这些参数才能成功调用 http 服务。这些参数包括:
服务的 URI
请求标头和内容
响应标头和内容
返回状态代码
安全调用的安全令牌
下表列出了所有 Http 活动通用的属性和参数。
属性 |
说明 |
---|---|
InArgument<string> Uri |
请求的 URI。 |
InArgument<DynamicValue> RequestHeaders |
请求消息的 Http 标头。 |
InArgument<SecurityToken> SecurityToken |
使用 GetS2SSecurityToken 活动启用基于声明的委派模式。 注意:这会将 Http 活动配置为使用 JsonWebTokens (JWT) 和 OAuth2 持有者令牌,因此该属性只能在使用 S2S 进行保护的范围中的工作流内部使用。使用实例化工作流的调用方(例如激活消息)的声明,并使用为部署配置的出站签名证书签署出站令牌。 |
bool RetryOnConnectionFailure |
使用指数回退算法启用由于超时或连接断开而失败的请求的自动重试。 |
ActivityFunc<HttpStatusCode, DynamicValue, DynamicValue, bool> HttpErrorHandler |
基于特定的 HttpStatusCode、响应标头和响应内容启用重试逻辑的处理。 |
OutArgument<DynamicValue> ResponseHeaders |
响应消息的 Http 标头。 |
OutArgument ResponseContent |
响应消息的正文内容。 |
OutArgument<HttpStatusCode> HttpStatusCode |
响应消息的 HttpStatusCode。 |
Http 活动
Workflow Manager 1.0 提供一组消息活动用于向 Http 服务发送出站消息。一般而言,每个活动代表一个 Http 谓词。下表列出了 Workflow Manager 1.0 中可用的 Http 活动。所有这些活动都具有Http 活动通用属性中所述的通用参数与属性集。除了这些通用属性和参数外,某些活动还具有“Other Arguments”列中所述的其他参数。
活动 |
说明 |
其他参数 |
---|---|---|
对 Http 服务调用 GET |
||
对 Http 服务调用 POST |
InArgument RequestContent |
|
对 Http 服务调用 PUT |
InArgument RequestContent |
|
对 Http 服务调用 DELETE |
||
可使用 eTag 执行更新操作的第一类标头 |
InArgument RequestContent InArgument<String> Etag |
指定请求和响应的内容
在提供请求和响应内容时,你可以传递一个基元对象(例如,将要序列化为请求内容的字符串、数字或日期)或 DynamicValue。
Http 活动与 DynamicValue 深度集成:对于请求,提供的 DynamicValue 将被自动序列化为其 Json 表示形式,并设置为 Http 调用的请求内容。对于响应,从服务器返回的内容将被加载到 DynamicValue 中(仅当响应作为有效的 Json 返回时,这才起作用)。
以下代码示例显示了如何使用 HttpGet 将 Netflix 中的信息置于 DynamicValue 中,并在活动中使用 HttpGet 的某些属性:
Variable<DynamicValue> response = new Variable<DynamicValue>();
Variable<string> name = new Variable<string>();
Variable<string> synopsis = new Variable<string>();
Variable<string> releaseYear = new Variable<string>();
Variable<string> result = new Variable<string>();
Activity sequence = new Sequence
{
Variables = { response, name, synopsis, releaseYear, result },
Activities =
{
// get the data from Netflix
new HttpGet
{
Uri = "http://odata.netflix.com/Catalog/Titles?$filter=Name%20eq%20'The%20Name%20of%20The%20Rose'",
ResponseContent = new OutArgument<DynamicValue>(response)
},
// read some properties from the result
new GetDynamicValueProperties
{
Source = response,
Properties =
{
{ "d/results(0)/Name", new OutArgument<string>(name) },
{ "d/results(0)/Synopsis", new OutArgument<string>(synopsis) },
{ "d/results(0)/ReleaseYear", new OutArgument<string>(releaseYear) }
}
},
// create a new string with the properties read the previous step
new FormatString
{
Format = "{0} ({1}): {2}",
Arguments =
{
new InArgument<string>(name),
new InArgument<string>(releaseYear),
new InArgument<string>(synopsis),
},
Result = result
}
}
};
注意 |
---|
接受并返回 Json 形式的内容的服务支持 DynamicValue 与 Http 活动集成。DynamicValue 集成当前不支持 AtomPub。 |
DynamicValue 中的 Http 标头
Http 标头已指定为 DynamicValue。要设置活动的标头,只需创建并传递包含你要使用的标头的 DynamicValue 即可。
Variable<DynamicValue> requestHeaders = new Variable<DynamicValue>();
Variable<DynamicValue> responseHeaders = new Variable<DynamicValue>();
var sequence = new Sequence
{
Variables = { requestHeaders, responseHeaders },
Activities =
{
// setup the headers
new BuildDynamicValue
{
Result = requestHeaders,
Properties =
{
{ "Accept", new InArgument<string>("text/plain") },
{ "Accept-Charset", new InArgument<string>("utf-8") },
}
},
// get the data from Netflix
new HttpGet
{
Uri = "https://contoso.com?var1=val",
RequestHeaders = requestHeaders,
ResponseHeaders = responseHeaders,
},
}
};