【发布时间】:2020-12-21 23:15:56
【问题描述】:
我正在尝试使用 C# 包装器异步调用我的 AX 2012 方法,但 AX 2012 方法没有执行。同步调用正确处理了相同的数据并正确执行。下面是 C# 中控制器的代码。为什么不执行异步方法?
我试图在没有等待和等待的情况下调用它。我尝试调试,但由于线程不同,它可能无法正常工作。
同步部分工作正常,但调用此 API 的 MS Flow 由于 Flow 的限制而超时。
您能告诉我如何使异步工作吗?我可以在 AX 2012 中使其异步吗?
//It dynamically sets the AIF Url and calls the method to consume AIF services
using SXA_FlowIntegrationWebAPI.Helpers;
using SXA_FlowIntegrationWebAPI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace SXA_FlowIntegrationWebAPI.Controllers
{
public class MainController : ApiController
{
[ActionName("Method")]
[HttpPost]
[Authorize]
public IHttpActionResult CallMethod(ClassMethodCallRequest request)
{
dynamic retValue;
using (var client = new AX2012.SXAFlowIntegrationServiceClient())
{
try
{
var callContext = new AX2012.CallContext();
callContext.Company = request.companyId;
callContext.LogonAsUser = User.Identity.Name;
client.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 00);
client.Endpoint.Address = new System.ServiceModel.EndpointAddress(request.aifURL);
if (request.methodName == "async")
{
retValue = "";
//client.callMethodAsync(callContext, request.className, request.methodName, request.dataJsonStr);
CallMethodAsyncCustom(client, callContext, request);
}
else
{
retValue = client.callMethod(callContext, request.className, request.methodName, request.dataJsonStr);
}
}
catch(Exception e)
{
return Json(new ClassMethodCallResponse
{
status = "Error",
userName = User.Identity.Name,
className = request.className,
methodName = request.methodName,
aifURL = request.aifURL,
error = e
});
}
}
return Json(new ClassMethodCallResponse
{
status = "Success",
userName = User.Identity.Name,
className = request.className,
methodName = request.methodName,
aifURL = request.aifURL,
data = retValue,
});
}
public static async System.Threading.Tasks.Task<string> CallMethodAsyncCustom(AX2012.SXAFlowIntegrationServiceClient client, AX2012.CallContext callContext, ClassMethodCallRequest request)
{
await System.Threading.Tasks.Task.Run(() => client.callMethodAsync(callContext, request.className, request.methodName, request.dataJsonStr));
return "Completed";
}
}
}
【问题讨论】:
-
只是为了排除显而易见的问题,您是在 AX 中进行增量还是填充
CIL编译? -
我执行了增量
标签: c# web-services dynamics-ax-2012 power-automate