zoukankan      html  css  js  c++  java
  • 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的源代码。

    点击下载此文件

  • 相关阅读:
    初学Cocos2dx
    炸弹人NABCD分析
    求二维整数数组中最大联通子数组的和
    大道之简读书笔记1
    求首位相连二维数组最大子矩阵的和
    求首位相连一维数组最大子数组的和
    求二维数组最大子数组的和
    程序员修炼之道读后感3
    电梯调度需求分析
    课堂作业第四周课上作业二
  • 原文地址:https://www.cnblogs.com/daxnet/p/1686947.html
Copyright © 2011-2022 走看看