Batch processing 使用批处理作业运行web服务时出现问题?

Batch processing 使用批处理作业运行web服务时出现问题?,batch-processing,axapta,x++,dynamics-ax-2012,dynamics-ax-2012-r2,Batch Processing,Axapta,X++,Dynamics Ax 2012,Dynamics Ax 2012 R2,我使用visual studio使用了一个web服务,并在AX 2012中使用托管代码调用了该服务。 现在,如果我在一个简单的作业中运行代码,如下所示: static void CurrencyService(Args _args) { CurrencyConvert.Currency_Convert.CurrencyServiceClient convertcurrency; CurrencyConvert.Currency_Convert.Currency currency;

我使用visual studio使用了一个web服务,并在AX 2012中使用托管代码调用了该服务。 现在,如果我在一个简单的作业中运行代码,如下所示:

static void CurrencyService(Args _args)
{
   CurrencyConvert.Currency_Convert.CurrencyServiceClient convertcurrency;
   CurrencyConvert.Currency_Convert.Currency currency;
   System.ServiceModel.Description.ServiceEndpoint endPoint;
   System.Type type;
   System.Exception ex;
   str s1;

try
{
    type = CLRInterop::getType('CurrencyConvert.Currency_Convert.CurrencyServiceClient');
    convertcurrency = AifUtil::createServiceClient(type);

    endPoint = convertcurrency.get_Endpoint();
   // endPoint.set_Address(new System.ServiceModel.EndpointAddress("http://localhost/HelloWorld"));
    currency = convertcurrency.GetConversionRate(CurrencyConvert.Currency_Convert.CurrencyCode::AUD,CurrencyConvert.Currency_Convert.CurrencyCode::INR );

  info(strFmt('%1', CLRInterop::getAnyTypeForObject(currency.get_Rate())));
}
 catch(Exception::CLRError)
{
    ex = CLRInterop::getLastException();
    info(CLRInterop::getAnyTypeForObject(ex.ToString()));
}
}
上述工作运行良好,并在信息日志中生成结果

现在,如果在batchjob类(扩展Runbasebatch类)下编写的代码与我们通常为任何批处理作业编写的代码相同,则会抛出一个错误,如下所示:

Microsoft.Dynamics.Ax.Xpp.ErrorException:类型为的异常 引发了“Microsoft.Dynamics.Ax.Xpp.ErrorException”

位于中的Dynamics.Ax.Application.BatchRun.runJobStatic(Int64 batchId) BatchRun.runJobStatic.xpp:第38行

在BatchRun::runJobStatic时(对象[])

在 Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(类型 类型、字符串方法名、对象[]参数)

在BatchIL.taskThreadEntry处(对象threadArg)

除已使用的web服务之外的其他批处理作业工作正常。 我已经尝试过很多方法,例如:将类的RunOn属性设置为“server”等。 我们使用的每个web服务都是这样。
有人对此有合适的解决方案吗???

我假设这与Dynamics Ax社区网站上的帖子相同。因此,阅读此处,错误与批处理无关,而是与以下内容相关:“在ServiceModel客户端配置部分中找不到引用约定“Currency\u Convert.ICurrencyService”的默认端点元素

这是因为正在AX32.exe.config文件中搜索终结点,而这不是您需要的终结点。您需要从与DLL关联的配置文件中获取它

为此,您需要在AX中以不同的方式构造客户端。您需要使用AIF util,因为这样会使用正确的配置。示例:

type= CLRInterop::getType('DynamicsAxServices.WebServices.ZipCode.USAZipCodeServiceRef.PostalCodeServiceClient'); 
postalServiceClient = AifUtil::createServiceClient(type);
除此之外,还有一件额外的事情需要处理。不同的环境需要不同的URL,这可以通过手动指定端点地址并让它使用系统参数来解决。(这样,您可以为DEV/TEST/PROD指定不同的配置)(注意:下面的端点地址是硬编码的,应该是一个参数)


我也遇到了同样的问题,终于解决了。 使用AOS服务帐户登录AOS机器,检查是否可以浏览internet。如果不能,则需要在IE中设置internet代理。
因此,基本上在AOS帐户下,进程无法连接到Web服务提供商。

我已经解决了这个问题。我只需在完成完整的cil后结束所有在线用户的会话并停止/启动AOS。在启动AOS服务之前,删除XPPIL和Appl文件可能会有所帮助。

是否创建了从AifDocumentService扩展的类并为其设置批处理作业这个类?@Setiaji据我所知,要在批处理作业中使用类,我认为我们必须创建扩展“RunBaseBatch”类的类。如果我错了,请纠正我??这是正确的,我告诉您可以在扩展AifDocumentService类的类内测试脚本,并为此类设置批处理作业。例如(在类声明中):类onHandServices扩展了AifDocumentService{}hi@MohdSaddafkhan-您的错误仅在批处理队列中运行时抛出,还是在通过批处理对话框手动运行时看到错误?@AnthonyBlake-问题仅在批处理队列中运行时发生,否则工作正常。
static void Consume_GetZipCodePlaceNameWithEndPoint(Args _args) 
{  
    DynamicsAxServices.WebServices.ZipCode.USAZipCodeServiceRef.PostalCodeServiceClient postalServiceClient;  
    DynamicsAxServices.WebServices.ZipCode.USAZipCodeServiceRef.PostalCodepostalCode;  
    System.ServiceModel.Description.ServiceEndpointendPoint;  
    System.ServiceModel.EndpointAddressendPointAddress;  
    System.Exceptionexception;  
    System.Typetype;  
    ;

    try
    {
        // Get the .NET type of the client proxy   
        type = CLRInterop::getType('DynamicsAxServices.WebServices.ZipCode.USAZipCodeServiceRef.PostalCodeServiceClient');

        // Let AifUtil create the proxy client because it uses the VSAssemblies path for the config file    
        postalServiceClient = AifUtil::createServiceClient(type);

        // Create and endpoint address, This should be a parameter stored in the system
        endPointAddress = new System.ServiceModel.EndpointAddress ("http://www.restfulwebservices.net/wcf/USAZipCodeService.svc");

        // Get the WCF endpoint    
        endPoint = postalServiceClient.get_Endpoint();

        // Set the endpoint address.    
        endPoint.set_Address(endPointAddress);

        // Use the zipcode to find a place name    
        postalCode = postalServiceClient. GetPostCodeDetailByPostCode("10001"); // 10001 is New York

        // Use the getAnyTypeForObject to marshal the System.String to an Ax anyType    
        // so that it can be used with info()    
        info(strFmt('%1', CLRInterop::getAnyTypeForObject(postalCode.get_ PlaceName())));  
    }  
    catch(Exception::CLRError)  
    {    
        // Get the .NET Type Exception     
        exception = CLRInterop::getLastException();

        // Go through the inner exceptions    
        while(exception)    
        {      
            // Print the exception to the infolog      
            info(CLRInterop::getAnyTypeForObject(exception.ToString()));

            // Get the inner exception for more details      
            exception = exception.get_InnerException();    
        }
    }
}