• X++中Web Service的动态调用


    所谓动态调用,最主要的是允许用户能够在系统中设置Web Service的服务地址,比如用户可以在AX中动态设置销售网站的Web Service地址,以便与第三方系统通信。

    本文介绍的方法其本质是使用COM创建SOAP request,然后以HTTP POST的方式,往指定的服务地址发送请求,进而实现Web Service的动态调用。请参考下面的例子:

    static void Job5(Args _args)
    {
        #localmacro.PARM_XML
            '<AuthenticationEMail>\%1</AuthenticationEMail>' +
            '<AuthenticationPassword>\%2</AuthenticationPassword>' +
            '<XmlInputRequestString>\%3</XmlInputRequestString>'
        #endmacro
    
        #localmacro.IPX_REQUEST
            '<AspDotNetStorefrontImport>' +
            '<XmlPackage Name="skin.helloworld.xml.config" OutputType="CDATA" />' +
            '</AspDotNetStorefrontImport>'
        #endmacro
    
        WebServiceClient wsClient = 
            new WebServiceClient('http://localhost/aspdotnetstorefront/ipx.asmx');
            
        XML request;
        XML response;
        ;
    
        // Creates the request XML string.
        request = strfmt(#PARM_XML, 
                        'admin@aspdotnetstorefront.com', 
                        '=]-[0p9oABCD', 
                        WebServiceClient::xmlEncode(#IPX_REQUEST));
    
        // Calls the DoItUsernamePwd web method and get the result.
        response = wsClient.invokeMethod(identifierstr(DoItUsernamePwd), 
                                         request, 
                                         'http://www.aspdotnetstorefront.com/');
    
        info(response);
    }

    以上例子展示了通过Web Service向AspDotNetStorefront应用程序发送一个处理指定的XmlPackage的请求。从中可以看到,AspDotNetStorefront所发布的ASP.NET Web Service地址是http://localhost/aspdotnetstorefront/ipx.asmx,我们首先拼装一个request xml,然后使用invokeMethod方法调用ipx.asmx中的DoItUsernamePwd方法。以下是这个方法的SOAP Schema描述:

    上图中的红框部分就是上面Job5中的Request XML,而绿框部分圈出的URL地址就是我们invokeMethod方法中的最后一个参数:namespace。

    附件是WebServiceClient类以及Job5的源代码。

    点击下载此文件

  • 相关阅读:
    后续阶段第二天
    后续阶段第一天
    冲刺第五天
    冲刺第四天
    冲刺第三天
    冲刺第二天
    第二阶段-冲刺第一天
    第一阶段项目总结
    冲刺(7)
    团队开发冲刺第一阶段_6
  • 原文地址:https://www.cnblogs.com/daxnet/p/1686947.html
Copyright © 2020-2023  润新知