• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            The power of C, the power of MD

            A problem is a chance to do your best
            posts - 11, comments - 22, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            使用gSOAP開發(fā)實例(1) 股票信息客戶端程序

            Posted on 2010-08-02 17:43 roy 閱讀(3400) 評論(6)  編輯 收藏 引用 所屬分類: C/C++
            電信provisioning系統(tǒng)中,常常需要與遠(yuǎn)程服務(wù)器實時交換一些數(shù)據(jù),以完成用戶的請求。由于簡單對象訪問協(xié)議(Simple Object Access Protocol, SOAP)的流行,許多涉及到第三方的應(yīng)用,我們一般都比較樂意使用SOAP來開發(fā)。不過,由于可能涉及到公司的機密,本系列教程的開發(fā)實例盡量采用在網(wǎng)上已經(jīng)公開的Web Service資源。
             
            gSOAP是一套開源的C/C++軟件工具包,使用它能夠很方便地開發(fā)SOAP網(wǎng)頁服務(wù)和基于XML的應(yīng)用程序,就像JAVA里面的axis。
             
            首先,我們需要從以下地址下載最新版本的gSOAP 2.7.17:
            https://sourceforge.net/projects/gsoap2/files/
             
            其次,gSOAP依賴于Bison和Flex,編譯gSOAP的時候會用到,如果沒有,從這里下載:
            Bison:http://www.gnu.org/software/bison/
            Flex:http://flex.sourceforge.net/
             
            關(guān)于這兩個工具包的安裝步驟可以參考最新的LFS手冊:
            http://www.linuxfromscratch.org/lfs/view/6.4/chapter06/bison.html
            http://www.linuxfromscratch.org/lfs/view/6.4/chapter06/flex.html
             
            如果不是root用戶,沒有安裝權(quán)限的話,可以在configure的時候使用--prefix=/path/to/your/own/directory,指定安裝路徑。裝好之后,修改用戶目錄的.profile文件,更改PATH和LD_LIBRARY_PATH環(huán)境變量,使得系統(tǒng)能夠正確搜索到你安裝后的可執(zhí)行文件和庫文件即可。
             
            這兩步準(zhǔn)備工作完成后,我們就可以開始編譯gSOAP。Linux下編譯安裝源代碼包無非就是tar zxvf xxx,configure,make,make install,由于我不是root用戶,沒有安裝的權(quán)限,那么不執(zhí)行make install也可以使用gSOAP開發(fā)程序,只不過使用的時候常常需要指定路徑。
             
            現(xiàn)在我們的目標(biāo)是開發(fā)一個獲取股票信息的客戶端程序。服務(wù)端采用webxml開發(fā)的WSDL,其URL是:http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl
             
            首先,在gsoap-2.7/gsoap/wsdl/下創(chuàng)建一個stock目錄
            -bash-3.2$ mkdir -p stock
             
            改變當(dāng)前路徑為stock
            -bash-3.2$ cd stock
             
            使用wsdl2h生成stock.h,如果希望生成純C代碼,需要加上-c參數(shù),否則,將會生成C++代碼
            -bash-3.2$ ../wsdl2h -c -o stock.h http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl
             
            **  The gSOAP WSDL/Schema processor for C and C++, wsdl2h release 1.2.17
            **  Copyright (C) 2000-2010 Robert van Engelen, Genivia Inc.
            **  All Rights Reserved. This product is provided "as is", without any warranty.
            **  The wsdl2h tool is released under one of the following two licenses:
            **  GPL or the commercial license by Genivia Inc. Use option -l for more info.
             
            Saving stock.h
             
            Cannot open file 'typemap.dat'
            Problem reading type map file 'typemap.dat'.
            Using internal type definitions for C instead.
             
             
            Connecting to 'http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl' to retrieve WSDL/XSD...
            Connected, receiving...
            Done reading 'http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl'
             
            To complete the process, compile with:
            > soapcpp2 stock.h
             
            然后,使用soapcpp2生成客戶端存根程序和相關(guān)的頭文件、資源文件,由于我們只開發(fā)客戶端程序,所以可以指定-C參數(shù)
            -bash-3.2$ ../../bin/linux386/soapcpp2 -C stock.h
             
            **  The gSOAP code generator for C and C++, soapcpp2 release 2.7.17
            **  Copyright (C) 2000-2010, Robert van Engelen, Genivia Inc.
            **  All Rights Reserved. This product is provided "as is", without any warranty.
            **  The soapcpp2 tool is released under one of the following three licenses:
            **  GPL, the gSOAP public license, or the commercial license by Genivia Inc.
             
            Saving soapStub.h annotated copy of the input declarations
            Saving soapH.h interface declarations
            Saving soapC.c XML serializers
            Saving soapClient.c client calling stubs
            Saving soapClientLib.c client stubs with serializers (use only for libs)
            Using ns2 service name: ChinaStockWebServiceSoap
            Using ns2 service style: document
            Using ns2 service encoding: literal
            Using ns2 service location: http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx
            Using ns2 schema namespace: http://WebXml.com.cn/ChinaStockWebServiceSoap
            Saving ChinaStockWebServiceSoap.getStockImageByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap.getStockImageByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap.getStockImageByteByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap.getStockImageByteByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap.getStockImage_kByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap.getStockImage_kByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap.getStockImage_kByteByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap.getStockImage_kByteByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap.getStockInfoByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap.getStockInfoByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap.nsmap namespace mapping table
            Using ns3 service name: ChinaStockWebServiceSoap12
            Using ns3 service style: document
            Using ns3 service encoding: literal
            Using ns3 service location: http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx
            Using ns3 schema namespace: http://WebXml.com.cn/ChinaStockWebServiceSoap12
            Saving ChinaStockWebServiceSoap12.getStockImageByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap12.getStockImageByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap12.getStockImageByteByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap12.getStockImageByteByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap12.getStockImage_kByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap12.getStockImage_kByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap12.getStockImage_kByteByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap12.getStockImage_kByteByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap12.getStockInfoByCode.req.xml sample SOAP/XML request
            Saving ChinaStockWebServiceSoap12.getStockInfoByCode.res.xml sample SOAP/XML response
            Saving ChinaStockWebServiceSoap12.nsmap namespace mapping table
             
            Compilation successful
             
            接著,就可以利用存根程序提供的接口編寫客戶端程序了,過程相當(dāng)簡單。
            #include "soapH.h"
            #include 
            "ChinaStockWebServiceSoap12.nsmap"

            int main(int argc, char **argv) {
                    
            if ( argc != 2 ) {
                            printf(
            "Usage: %s stock_code\n", argv[0]);
                            exit(
            -1);
                    }

                    
            struct soap soap;
                    soap_init(
            &soap);
                    
            struct _ns1__getStockInfoByCode request;
                    
            struct _ns1__getStockInfoByCodeResponse response;

                    request.theStockCode 
            = argv[1];
                    
            if ( soap_call___ns3__getStockInfoByCode(&soap, NULL, NULL, &request, &response) == SOAP_OK ) {
                            
            int element_counter = response.getStockInfoByCodeResult->__sizestring;
                            
            int i = 0;
                            
            for ( i = 0; i < element_counter; i++ ) {
                                    
            switch ( i ) {
                                            
            case 0  : printf("Stock code        : "); break;
                                            
            case 1  : printf("Stock name        : "); break;
                                            
            case 2  : printf("Timestamp         : "); break;
                                            
            case 3  : printf("Latest price      : "); break;
                                            
            case 4  : printf("Closing price T-1 : "); break;
                                            
            case 5  : printf("Opening price     : "); break;
                                            
            case 6  : printf("Ups and downs     : "); break;
                                            
            case 7  : printf("Mininum price     : "); break;
                                            
            case 8  : printf("Maxinum price     : "); break;
                                            
            case 9  : printf("Amount of up/down : "); break;
                                            
            case 10 : printf("Trading volume    : "); break;
                                            
            case 11 : printf("Trading amount    : "); break;
                                            
            case 12 : printf("Buy price         : "); break;
                                            
            case 13 : printf("Sell price        : "); break;
                                            
            case 14 : printf("Agency trans      : "); break;
                                            
            case 15 : printf("Buy  1            : "); break;
                                            
            case 16 : printf("Buy  2            : "); break;
                                            
            case 17 : printf("Buy  3            : "); break;
                                            
            case 18 : printf("Buy  4            : "); break;
                                            
            case 19 : printf("Buy  5            : "); break;
                                            
            case 20 : printf("Sell 1            : "); break;
                                            
            case 21 : printf("Sell 2            : "); break;
                                            
            case 22 : printf("Sell 3            : "); break;
                                            
            case 23 : printf("Sell 4            : "); break;
                                            
            case 24 : printf("Sell 5            : "); break;
                                            
            default : break;
                                    }
                                    printf(
            "%s\n", response.getStockInfoByCodeResult->string[i]);
                            }
                    }
                    
            else {
                            soap_print_fault(
            &soap, stderr);
                    }

                    soap_destroy(
            &soap);
                    soap_end(
            &soap);
                    soap_done(
            &soap);
                    
            return 0;
            }

            基本上都是套用差不多的格式,不清楚具體參數(shù)意義的話,可以參考soapcpp2生成的存根程序及其頭文件。把上述代碼保存為stock.c,編譯命令是:
            gcc -O2 -o stock stock.c soapC.c soapClient.c ../../stdsoap2.c -I../.. -L../.. –lgsoap
             
            可以看到,編譯時,除了stock.c,還需要包括存根程序soapC.c和soapClient.c,以及gSOAP運行時引擎stdsoap2.c,另外還需要指定頭文件搜索路徑、庫文件搜索路徑,以及告訴編譯器,鏈接libgsoap
             
            一切正常的話,就大功告成了:
            -bash-3.2$ ./stock sh600000
            Stock code        : sh600000
            Stock name        : 浦發(fā)銀行
            Timestamp         : 2010-07-08 15:02:07
            Latest price      : 13.79
            Closing price T-1 : 13.76
            Opening price     : 13.88
            Ups and downs     : 0.03
            Mininum price     : 13.73
            Maxinum price     : 14.06
            Amount of up/down : 0.22%
            Trading volume    : 451017.84
            Trading amount    : 62602.5809
            Buy price         : 13.78
            Sell price        : 13.79
            Agency trans      : 34.07%
            Buy  1            : 13.78 / 1622.88
            Buy  2            : 13.77 / 687.10
            Buy  3            : 13.76 / 785.00
            Buy  4            : 13.75 / 1430.00
            Buy  5            : 13.74 / 264.00
            Sell 1            : 13.79 / 33.70
            Sell 2            : 13.80 / 64.17
            Sell 3            : 13.81 / 290.80
            Sell 4            : 13.82 / 1318.70
            Sell 5            : 13.83 / 647.70

             

            http://blog.csdn.net/yui/archive/2010/07/08/5721877.aspx

            Feedback

            # re: 使用gSOAP開發(fā)實例(1) 股票信息客戶端程序  回復(fù)  更多評論   

            2010-08-03 08:26 by right
            gSOAP的許可協(xié)議有點讓人糾結(jié)~

            # re: 使用gSOAP開發(fā)實例(1) 股票信息客戶端程序  回復(fù)  更多評論   

            2010-08-03 09:50 by roy
            @right

            此話怎講?

            # re: 使用gSOAP開發(fā)實例(1) 股票信息客戶端程序  回復(fù)  更多評論   

            2010-08-03 17:32 by www
            @roy
            gpl 或者 商業(yè)授權(quán)。
            不能不掏錢用來開發(fā)非GPL的程序

            # re: 使用gSOAP開發(fā)實例(1) 股票信息客戶端程序  回復(fù)  更多評論   

            2010-08-04 09:30 by roy
            @www

            這樣啊,但是我在別的地方看到這段話,好像GPL并不意味著要收費呀

            使用GPL協(xié)議的代碼制作的程序并非不能拿來賣錢,事實上RMS開始自由運動的第一筆經(jīng)費就是通過售賣附在磁碟上的Emacs賺來的。GPL的主要規(guī)定在于源代碼必須自由公開。

            http://www.linuxdiyf.com/viewarticle.php?id=179559

            # re: 使用gSOAP開發(fā)實例(1) 股票信息客戶端程序  回復(fù)  更多評論   

            2010-08-04 09:48 by www
            @roy
            GPL授權(quán)的程序是可以用來賣錢的,但是你必須以GPL授權(quán)的方式公開你產(chǎn)品的源代碼。

            # re: 使用gSOAP開發(fā)實例(1) 股票信息客戶端程序  回復(fù)  更多評論   

            2010-08-04 11:35 by roy
            @www

            明白了,謝謝你
            国产亚洲精品久久久久秋霞| 欧美久久综合性欧美| 国产L精品国产亚洲区久久| 热re99久久精品国99热| 久久人人添人人爽添人人片牛牛| 狠狠久久综合伊人不卡| 精品久久久久久无码人妻热| 久久本道综合久久伊人| 久久本道久久综合伊人| 欧美伊人久久大香线蕉综合69| 久久久久久久综合综合狠狠| 久久久久成人精品无码| 久久久久九九精品影院| 色99久久久久高潮综合影院| 国内精品久久久久影院老司| 中文字幕日本人妻久久久免费 | 狠狠色丁香久久婷婷综合图片| 伊人久久大香线蕉成人| 久久人人爽人人爽人人av东京热| 亚洲午夜无码久久久久| 久久久久人妻一区二区三区vr | 久久午夜电影网| 久久精品国产第一区二区| 精品久久久久久无码不卡| 久久精品人人槡人妻人人玩AV| 色噜噜狠狠先锋影音久久| 少妇被又大又粗又爽毛片久久黑人| 7777久久久国产精品消防器材| 久久精品国产亚洲av高清漫画| 久久精品国产第一区二区| 亚洲国产香蕉人人爽成AV片久久| 婷婷伊人久久大香线蕉AV| 国产成人精品综合久久久| 2020国产成人久久精品| 久久国产精品久久久| 中文国产成人精品久久不卡| 岛国搬运www久久| 久久久久久人妻无码| 欧美伊人久久大香线蕉综合| 中文字幕一区二区三区久久网站| 四虎国产精品成人免费久久|