I have a new retail server extension that does a realtime call. My call to the method in X++ is as follows. I followed the example of StoreHoursDataService and GetFulfillmentPackgingslipService examples.
"
InvokeExtensionMethodRealtimeRequest extensionRequest = new InvokeExtensionMethodRealtimeRequest(
"TMCGetReservedOrders",
request.WhseId);
InvokeExtensionMethodRealtimeResponse response = await request.RequestContext.ExecuteAsync<InvokeExtensionMethodRealtimeResponse>(extensionRequest).ConfigureAwait(false);
ReadOnlyCollection<object> results = response.Result;
success = Convert.ToBoolean(results[0]);
"
I am supposed to be able to retrieve the "success" flag using Convert.ToBoolean(results[0]).
However the eventviewer for the Commerce-RetailServer gives the error:
***
An error occurred during the Retail Server Request. RequestUri: <URL>/Commerce/ReservedOrders/TMCGetReservedOrdersAction?$top=250&api-version=7.3. RequestId: 947f1dd4-4fe8-c399-ec87-e3331596158b. Exception: System.FormatException: String was not recognized as a valid Boolean.
at System.Boolean.Parse(String value)
at System.String.System.IConvertible.ToBoolean(IFormatProvider provider)
at TMCReservedOrdersViewCRT.GetReservedOrderService.<Process>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.<Execute>d__38`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.<Execute>d__38`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at TMCRetailServer.GetReservedOrdersView.GetReservedOrdersController.<TMCGetReservedOrdersAction>d__0.MoveNext() in C:\Source\RetailSDK\TMCBackendExtensions\TMC_OrderFulfillmentProjects\TMCRetailServer.GetReservedOrdersView\GetReservedOrdersController.cs:line 31
***
If I change my approach and read "results" as follow, then the error disappears but the results.Count returns a 1 instead of 3:
int vCnt = 1;
foreach (object vObj in results)
{
if (vCnt == 1)
{
bool vConverted = Boolean.TryParse(vObj.ToString(), out success);
if (vConverted == false)
{
success = false;
}
}
break;
}
If I add a test job to my project in X++ and in its Main-method add the following code that calls the method that the InvokeExtensionMethod calls, then it returns values :
static void main (Args _args)
{
boolean vOK = true;
str vResult = '';
str errorMessage = '';
InventLocationId whseId;
whseId = 'KCY';
[vOK, errorMessage, vResult] = RetailTransactionServiceEx::TMCGetReservedOrders(whseId);
}
As you can see from the above image it returns a True for success and it returns 3 entries in the container.
So why won't the InvokeExtensionMethod not return the 3 values?
I even changed my class to extend from SingleAsynRequestHandler, same as GetFulfillmentPackgingslipService :
public class GetReservedOrderService : SingleAsyncRequestHandler<GetReservedOrdersRequest>
I first had it as : public class GetReservedOrderService : IRequestHandler , and called the InvokeExtensionMethod as following, but the error happens for both:
***
InvokeExtensionMethodRealtimeRequest extensionRequest = new InvokeExtensionMethodRealtimeRequest("TMCGetReservedOrders", request.WhseId);
InvokeExtensionMethodRealtimeResponse response = request.RequestContext.Execute<InvokeExtensionMethodRealtimeResponse>(extensionRequest);
ReadOnlyCollection<object> results = response.Result;
***
I'm running v10.0.12 in case it is important.
Any help is much appreciated to solve this error.