• <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++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
            電信provisioning系統(tǒng)中,常常需要與遠(yuǎn)程服務(wù)器實(shí)時(shí)交換一些數(shù)據(jù),以完成用戶(hù)的請(qǐng)求。由于簡(jiǎn)單對(duì)象訪(fǎng)問(wèn)協(xié)議(Simple Object Access Protocol, SOAP)的流行,許多涉及到第三方的應(yīng)用,我們一般都比較樂(lè)意使用SOAP來(lái)開(kāi)發(fā)。不過(guò),由于可能涉及到公司的機(jī)密,本系列教程的開(kāi)發(fā)實(shí)例盡量采用在網(wǎng)上已經(jīng)公開(kāi)的Web Service資源。
             
            上文已經(jīng)交待了gSOAPLinux環(huán)境下的編譯方法和客戶(hù)端的實(shí)例程序,本文繼續(xù)講解其服務(wù)端程序的開(kāi)發(fā)。由于不可能獲得真正的數(shù)據(jù)庫(kù)內(nèi)容,我們?cè)O(shè)定的目標(biāo)是,所有返回的內(nèi)容都是客戶(hù)端傳入的股票代碼。
             
            首先,在gsoap-2.7/gsoap/wsdl/下創(chuàng)建一個(gè)stock_server目錄
            -bash-3.2$ mkdir -p stock_server
             
            改變當(dāng)前路徑為stock_server
            -bash-3.2$ cd stock_server
             
            仍然使用wsdl2h生成基于純C代碼的stock.h
            -bash-3.2$ ../wsdl2h -c -o stock.h http://webservice.webxml.com.cn/WebServices/ChinaStockWebService.asmx?wsdl
             
            然后,生成服務(wù)端存根程序,并且不生成xml文件和soapServerLib.c
            -bash-3.2$ ../../bin/linux386/soapcpp2 -S -L -x 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 soapServer.c server request dispatcher
            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.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.nsmap namespace mapping table
             
            Compilation successful
             
            服務(wù)端的主程序稍微比客戶(hù)端復(fù)雜些,因?yàn)檫€要處理客戶(hù)端的其他請(qǐng)求,至少要有其函數(shù)體,否則編譯時(shí)會(huì)報(bào)錯(cuò)。

            #include "soapH.h"
            #include 
            "ChinaStockWebServiceSoap12.nsmap"

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

                
            struct soap soap;
                soap_init(
            &soap);
                
            int m, s;
                
            if ( (m = soap_bind(&soap, NULL, port, 100)) < 0 ) {
                    soap_print_fault(
            &soap, stderr);
                }
                
            else {
                    printf(
            "Socket connect successfully: master socket = %d\n", m);
                    
            int i = 0;
                    
            while ( 1 ) {
                        
            if ( (s = soap_accept(&soap)) < 0 ) {
                            soap_print_fault(
            &soap, stderr);
                            
            break;
                        }
                        printf(
            "Connection %d accepted from IP = %d.%d.%d.%d, slave socket = %d\n"++i, (soap.ip >> 24& 0xff, (soap.ip >> 16& 0xff, (soap.ip >> 8& 0xff, soap.ip & 0xff, s);
                        
            if ( soap_serve(&soap) != SOAP_OK ) {
                            soap_print_fault(
            &soap, stderr);
                            
            break;
                        }
                        soap_end(
            &soap);
                    }
                }
                soap_done(
            &soap);
            }

            int __ns3__getStockInfoByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockInfoByCode *request,
                
            struct _ns1__getStockInfoByCodeResponse *response) {
                
            int element_counter = 25;
                response
            ->getStockInfoByCodeResult = (struct ns1__ArrayOfString *) malloc(sizeof(struct ns1__ArrayOfString));
                response
            ->getStockInfoByCodeResult->__sizestring = element_counter;
                response
            ->getStockInfoByCodeResult->string = (char **) malloc(sizeof(char ** element_counter);
                
            int i = 0;
                
            for ( i = 0; i < element_counter; i++ ) {
                    response
            ->getStockInfoByCodeResult->string[i] = (char *) malloc(sizeof(char* 32);
                    strcpy(response
            ->getStockInfoByCodeResult->string[i], request->theStockCode);
                }
                
            return SOAP_OK;
            }

            int __ns3__getStockImage_USCOREkByteByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockImage_USCOREkByteByCode *request,
                
            struct _ns1__getStockImage_USCOREkByteByCodeResponse *response) {
                
            return SOAP_OK;
            }

            int __ns3__getStockImage_USCOREkByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockImage_USCOREkByCode *request,
                
            struct _ns1__getStockImage_USCOREkByCodeResponse *response) {
                
            return SOAP_OK;
            }

            int __ns3__getStockImageByteByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockImageByteByCode *request,
                
            struct _ns1__getStockImageByteByCodeResponse *response) {
                
            return SOAP_OK;
            }

            int __ns3__getStockImageByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockImageByCode *request,
                
            struct _ns1__getStockImageByCodeResponse *response) {
                
            return SOAP_OK;
            }

            int __ns2__getStockInfoByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockInfoByCode *request,
                
            struct _ns1__getStockInfoByCodeResponse *response) {
                
            int element_counter = 25;
                response
            ->getStockInfoByCodeResult = (struct ns1__ArrayOfString *) malloc(sizeof(struct ns1__ArrayOfString));
                response
            ->getStockInfoByCodeResult->__sizestring = element_counter;
                response
            ->getStockInfoByCodeResult->string = (char **) malloc(sizeof(char ** element_counter);
                
            int i = 0;
                
            for ( i = 0; i < element_counter; i++ ) {
                    response
            ->getStockInfoByCodeResult->string[i] = (char *) malloc(sizeof(char* 32);
                    strcpy(response
            ->getStockInfoByCodeResult->string[i], request->theStockCode);
                }
                
            return SOAP_OK;
            }

            int __ns2__getStockImage_USCOREkByteByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockImage_USCOREkByteByCode *request,
                
            struct _ns1__getStockImage_USCOREkByteByCodeResponse *response) {
                
            return SOAP_OK;
            }

            int __ns2__getStockImage_USCOREkByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockImage_USCOREkByCode *request,
                
            struct _ns1__getStockImage_USCOREkByCodeResponse *response) {
                
            return SOAP_OK;
            }

            int __ns2__getStockImageByteByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockImageByteByCode *request,
                
            struct _ns1__getStockImageByteByCodeResponse *response) {
                
            return SOAP_OK;
            }

            int __ns2__getStockImageByCode(
                
            struct soap *soap,
                
            struct _ns1__getStockImageByCode *request,
                
            struct _ns1__getStockImageByCodeResponse *response) {
                
            return SOAP_OK;
            }


            值得注意的是,如果項(xiàng)目中存在多個(gè)name space,最好把全部name space的相關(guān)方法都進(jìn)行編碼,否則可能出現(xiàn)意想不到的錯(cuò)誤:客戶(hù)端明明是調(diào)用ns3的方法,但是服務(wù)端卻使用了ns2的方法來(lái)提供服務(wù)。這一點(diǎn)我也比較費(fèi)解,可能與wsdl本身的寫(xiě)法有關(guān)。

             

            上述服務(wù)端程序的編譯命令是

            gcc -O2 -o stock_server stock_server.c soapC.c soapServer.c ../../stdsoap2.c -I../.. -L../.. -lgsoap

             

            同時(shí),要把上文的客戶(hù)端程序修改一下,支持指定的end point,不指定end point再取默認(rèn)的end point

            #include "soapH.h"
            #include 
            "ChinaStockWebServiceSoap12.nsmap"

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

                
            struct soap soap;
                soap_init(
            &soap);
                soap_set_mode(
            &soap, SOAP_C_UTFSTRING);
                
            struct _ns1__getStockInfoByCode request;
                
            struct _ns1__getStockInfoByCodeResponse response;

                request.theStockCode 
            = argv[1];
                
            char *endpoint = NULL;
                
            if ( argc == 3 )
                    endpoint 
            = argv[2];
                
            if ( soap_call___ns3__getStockInfoByCode(&soap, endpoint, 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;
            }


            使服務(wù)端程序在某一高位端口下運(yùn)行,比如
            -bash-3.2$ ./stock_server 6883
            Socket connect successfully: master socket = 3
             
            另起一個(gè)窗口執(zhí)行客戶(hù)端程序,并且指定end point
            -bash-3.2$ ./stock sh600000 http://localhost:6883
            Stock code        : sh600000
            Stock name        : sh600000
            Timestamp         : sh600000
            Latest price      : sh600000
            Closing price T-1 : sh600000
            Opening price     : sh600000
            Ups and downs     : sh600000
            Mininum price     : sh600000
            Maxinum price     : sh600000
            Amount of up/down : sh600000
            Trading volume    : sh600000
            Trading amount    : sh600000
            Buy price         : sh600000
            Sell price        : sh600000
            Agency trans      : sh600000
            Buy  1            : sh600000
            Buy  2            : sh600000
            Buy  3            : sh600000
            Buy  4            : sh600000
            Buy  5            : sh600000
            Sell 1            : sh600000
            Sell 2            : sh600000
            Sell 3            : sh600000
            Sell 4            : sh600000
            Sell 5            : sh600000
             
            成功!

            久久青青草原精品影院| 欧美日韩精品久久久免费观看| 噜噜噜色噜噜噜久久| 久久精品人妻中文系列| 奇米综合四色77777久久| 一本久久久久久久| 人妻系列无码专区久久五月天| 久久无码AV一区二区三区| 亚洲精品无码久久久影院相关影片 | 97久久国产亚洲精品超碰热| 97久久精品午夜一区二区| 国产农村妇女毛片精品久久| 人妻无码精品久久亚瑟影视| 94久久国产乱子伦精品免费| 久久一本综合| 四虎国产精品免费久久5151| 久久精品国产99国产精品导航| 四虎国产精品免费久久5151| 伊人久久无码中文字幕| 精品久久久久一区二区三区| 久久精品中文闷骚内射| 日本亚洲色大成网站WWW久久| 久久99国产亚洲高清观看首页| 亚洲国产精品成人久久蜜臀| 热久久国产精品| 91久久精品91久久性色| 色狠狠久久AV五月综合| 亚洲精品视频久久久| 久久AAAA片一区二区| 97久久久精品综合88久久| 久久久免费精品re6| 囯产极品美女高潮无套久久久| 亚洲欧洲精品成人久久曰影片| 国产成人综合久久精品尤物| 久久精品国产亚洲网站| 精品久久久久久亚洲精品| 亚洲精品蜜桃久久久久久| 久久久久久久久久久久久久| 久久久噜噜噜久久中文字幕色伊伊| 欧美日韩精品久久久久| 狠狠色丁香婷婷久久综合|