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

时间:2013-12-09 14:01:13

标签: 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;
   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(Object [])

     

在   Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(类型   type,String MethodName,Object []参数)

     

在BatchIL.taskThreadEntry(Object threadArg)

除了使用过的Web服务之外的其他批处理作业正常工作。 我已经尝试了很多东西,例如:类的RunOn属性设置为“server”等。 我们消费的每个Web服务都是这种情况。 有人有适当的解决方案??

3 个答案:

答案 0 :(得分:1)

我假设这与Dynamics Ax社区网站帖子上的相同。因此,在那里阅读,错误与批处理无关,但与以下内容有关:“无法在ServiceModel客户端配置部分找到引用合同'Currency_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指定不同的配置)(注意:端点地址下面是硬编码的,应该是参数)

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();    
        }
    }
}

答案 1 :(得分:1)

我遇到了同样的问题,最终解决了。 使用AOS服务帐户登录AOS机器,检查是否可以浏览互联网。如果没有,那么你需要在IE中为互联网设置代理。 因此,基本上在AOS帐户下,进程无法连接到Webservice提供程序。

答案 2 :(得分:1)

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

相关问题