我正在尝试在UIPath中执行自定义asyncCodeActivity。添加了该包,传递了所有数据,但是UIPath仅在达到自定义活动时挂起,并且不会引发任何异常/或停止。我尝试使用CodeActivity和AsyncCodeActivity创建类库-我的活动应该进行多个APICall,但是我得到的结果是,当它到达我的自定义活动时,它只会停止,而不会转到下一个活动。有没有示例如何为UIPath创建异步自定义活动?当我尝试在UIpath之外进行测试时,我的类库工作正常。感谢您的帮助。
我的使用CodeActivity的类库:
public class AddInvoice : CodeActivity
{
[Category("Input")]
[RequiredArgument]
public InArgument<string> PickupZip { get; set; }
[Category("Output")]
[RequiredArgument]
public OutArgument<String> Output { get; set; }
public async Task<string> ApiTest(CodeActivityContext context)
{
try
{
var origin = await GoogleAPIWrapper.GetAddressByZip(PickupZip.Get(context));
string PickupAddress;
string DeliveryAddress;
var inv = new IList();
if (origin.StatusId >= 0)
{
invoice.PickupCity = origin.Locality;
invoice.PickupState = origin.AdminLevel1;
}
else
{
invoice.PickupCity = null;
invoice.PickupState = null;
}
var tkn = token.Get(context);
var client = new HttpClient();
HttpClientHandler handler = new HttpClientHandler();
client = new HttpClient(handler, false);
client.BaseAddress = new Uri("http://test.test.com/");
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + tkn);
StringContent content = new StringContent(JsonConvert.SerializeObject(inv), Encoding.UTF8, "application/json");
var response = await client.PostAsync("api/insert/", content);
var resultContent = response.StatusCode;
Output.Set(context, resultContent.ToString());
}
catch (Exception e)
{
Output.Set(context, e.ToString());
}
return "ok";
}
protected override void Execute(CodeActivityContext context)
{
try
{
string result = ApiTest(context).GetAwaiter().GetResult();
}
catch (Exception e)
{
Output.Set(context, e.ToString());
}
}
public class IList
{
public string PickupState { get; set; }
public string PickupCity { get; set; }
}
}
答案 0 :(得分:2)
默认情况下,从CodeActivity派生的类是同步的。由于UiPath基于Windows Workflow,因此应该可以从AsyncCodeActivity类派生。
您没有明确要求它,但是由于本质上是在调用Web服务,因此请查看Web Activities软件包,尤其是HTTP Request。这还带有JSON反序列化。例如,您可以找到有关Web服务集成here的更多信息(免责声明:我是作者)。