我已成功通过API生成了三个文件。我用于执行此操作的代码在这里:
public SalesOrder GenerateAcumaticaLabels(string orderNbr, string reportType)
{
SalesOrder salesOrder = null;
using (ISoapClientProvider clientProvider = soapClientFactory.Create())
{
try
{
SalesOrder salesOrderToFind = new SalesOrder
{
OrderType = new StringSearch { Value = orderNbr.Split(OrderSeparator.SalesOrder).First() },
OrderNbr = new StringSearch { Value = orderNbr.Split(OrderSeparator.SalesOrder).Last() },
ReturnBehavior = ReturnBehavior.OnlySpecified,
};
salesOrder = clientProvider.Client.Get(salesOrderToFind) as SalesOrder;
InvokeResult invokeResult = new InvokeResult();
switch (reportType)
{
case "SFP":
invokeResult = clientProvider.Client.Invoke(salesOrder, new exportSFPReport());
break;
case "XFP":
invokeResult = clientProvider.Client.Invoke(salesOrder, new exportXFPReport());
break;
case "Tray":
invokeResult = clientProvider.Client.Invoke(salesOrder, new exportTrayLabelReport());
break;
default:
throw new Exception("Report Type not recognized");
}
ProcessResult processResult = clientProvider.Client.GetProcessStatus(invokeResult);
//Wait for the update to complete before we attempt to retrieve the files
while (processResult.Status == ProcessStatus.InProcess)
{
Thread.Sleep(1000); //pause for 1 second
processResult = clientProvider.Client.GetProcessStatus(invokeResult);
}
}
catch (Exception ex)
{
IntegraLogging.LogError("Error generating sales order labels: " + ex.Message, EventID.Acumatica, ex, MethodInfo.GetCurrentMethod().Name, Departments.IT,
LocalEnvironment, "salesOrderNbr", salesOrder.OrderNbr.Value, null);
}
}
return salesOrder;
}
尝试检索已生成的文件时,.GetFiles出现错误:
public Dictionary<string, Byte[]> RetrieveAcumaticaLabels(string orderNbr)
{
File[] files = null;
SalesOrder salesOrder = null;
Dictionary<string, Byte[]> filesDictionary = new Dictionary<string, byte[]>();
using (ISoapClientProvider clientProvider = soapClientFactory.Create())
{
try
{
SalesOrder salesOrderToFind = new SalesOrder
{
OrderType = new StringSearch { Value = orderNbr.Split(OrderSeparator.SalesOrder).First() },
OrderNbr = new StringSearch { Value = orderNbr.Split(OrderSeparator.SalesOrder).Last() },
ReturnBehavior = ReturnBehavior.OnlySpecified,
};
salesOrder = clientProvider.Client.GetList(salesOrderToFind).Cast<SalesOrder>().FirstOrDefault();
//Get the files and put the content into a dictionary by name
files = clientProvider.Client.GetFiles(salesOrder) as IntegraDataServices.AcumaticaOpticsExt.File[];
foreach (File file in files)
{
//Store the filename as just the filename, location info excluded, so we don't have to rebuild it later to retrieve it.
string[] fileName = file.Name.Split(System.IO.Path.DirectorySeparatorChar);
//Only store the file once, in case of dupes
if (!filesDictionary.ContainsKey(fileName[2]))
{
filesDictionary.Add(fileName[2], file.Content);
}
}
}
catch (Exception ex)
{
IntegraLogging.LogError("Error retrieving sales order labels: " + ex.Message, EventID.Acumatica, ex, MethodInfo.GetCurrentMethod().Name, Departments.IT,
LocalEnvironment, "salesOrderNbr", orderNbr, null);
}
}
return filesDictionary;
}
这是我遇到的错误:
System.InvalidOperationException: Sequence contains more than one matching element
at PX.Api.ContractBased.Soap.WebApiSoapController.Post(ISoapSystemContract systemContract, XmlReader requestReader, String serviceNamespace, String internalNamespace, MethodInfo method, Func`1 serviceFactory, IEdmModel edmModel)
at PX.Api.ContractBased.Soap.WebApiSoapController.<Post>d__8.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 PX.Api.ContractBased.Soap.WebApiSoapController.<Login>d__6.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 System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`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 System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>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 System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.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 System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
我能够成功地从Kit Assembly中生成和检索文件;我不确定是什么原因导致了销售订单中的问题。
答案 0 :(得分:0)
我测试了以下示例,该示例在我的环境中有效。这可能需要进行故障排除。
尝试删除并重新添加服务引用,尝试多个销售订单,重新启动应用程序(IISReset)。
using System;
using System.Linq;
using System.ServiceModel;
using WebServiceTest.ServiceReference1;
namespace WebServiceTest
{
class Program
{
static void Main(string[] args)
{
using (DefaultSoapClient soapClient = new DefaultSoapClient(new BasicHttpBinding(BasicHttpSecurityMode.None)
{
AllowCookies = true,
Name = "DefaultSoap",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
},
new EndpointAddress("http://localhost/089253/entity/Default/17.200.001?wsdl")))
{
try
{
soapClient.Login("admin", "admin", "USA", null, null);
SalesOrder salesOrderToFind = new SalesOrder
{
OrderType = new StringSearch { Value = "SO" },
OrderNbr = new StringSearch { Value = "SO004519" },
ReturnBehavior = ReturnBehavior.OnlySpecified,
};
SalesOrder salesOrder = soapClient.GetList(salesOrderToFind).Cast<SalesOrder>().FirstOrDefault();
File[] file = soapClient.GetFiles(salesOrder) as File[];
soapClient.Logout();
}
catch (Exception ex)
{
try { soapClient.Logout(); } catch { }
throw ex;
}
}
}
}
}
答案 1 :(得分:0)
最终在这里起作用的是删除GetFiles之前的GetList调用。