• <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>

            woaidongmao

            文章均收錄自他人博客,但不喜標(biāo)題前加-[轉(zhuǎn)貼],因其丑陋,見(jiàn)諒!~
            隨筆 - 1469, 文章 - 0, 評(píng)論 - 661, 引用 - 0
            數(shù)據(jù)加載中……

            VC 的gSOAP例子

            1.1.1   gSOAP

            1.1.1.1     簡(jiǎn)介

            gSOAP編譯工具提供了一個(gè)SOAP/XML 關(guān)于C/C++ 語(yǔ)言的實(shí)現(xiàn),從而讓C/C++語(yǔ)言研發(fā)web服務(wù)或客戶(hù)端程式的工作變得輕松了很多。絕大多數(shù)的C++web服務(wù)工具包提供一組API函數(shù)類(lèi)庫(kù)來(lái)處理特定的SOAP數(shù)據(jù)結(jié)構(gòu),這樣就使得用戶(hù)必須改變程式結(jié)構(gòu)來(lái)適應(yīng)相關(guān)的類(lèi)庫(kù)。和之相反,gSOAP利用編譯器技術(shù)提供了一組透明化的SOAP API,并將和研發(fā)無(wú)關(guān)的SOAP實(shí)現(xiàn)細(xì)節(jié)相關(guān)的內(nèi)容對(duì)用戶(hù)隱藏起來(lái)。gSOAP的編譯器能夠自動(dòng)的將用戶(hù)定義的本地化的CC++數(shù)據(jù)類(lèi)型轉(zhuǎn)變?yōu)榉?/span>XML語(yǔ)法的數(shù)據(jù)結(jié)構(gòu),反之亦然。這樣,只用一組簡(jiǎn)單的API就將用戶(hù)從SOAP細(xì)節(jié)實(shí)現(xiàn)工作中解脫了出來(lái),能夠?qū)W⒑蛻?yīng)用程式邏輯的實(shí)現(xiàn)工作了。gSOAP編譯器能夠集成C/C++Fortran代碼(通過(guò)一個(gè)FortranC的接口),嵌入式系統(tǒng),其他SOAP程式提供的實(shí)時(shí)軟件的資源和信息;能夠跨越多個(gè)操作系統(tǒng),語(yǔ)言環(huán)境連同在防火墻后的不同組織。

                  gSOAP使編寫(xiě)web服務(wù)的工作最小化了。gSOAP編譯器生成SOAP的代碼來(lái)序列化或反序列化C/C++的數(shù)據(jù)結(jié)構(gòu)。gSOAP包含一個(gè)WSDL生成器,用他來(lái)為您的web服務(wù)生成web服務(wù)的解釋。gSOAP的解釋器及導(dǎo)入器能夠使用戶(hù)無(wú)需分析web服務(wù)的細(xì)節(jié)就能夠?qū)崿F(xiàn)一個(gè)客戶(hù)端或服務(wù)端程式。

            1.1.1.2     gSOAP+VC研發(fā)客戶(hù)端

            gSOAP是開(kāi)放的C/C++源碼的soap服務(wù)器實(shí)現(xiàn),本章節(jié)簡(jiǎn)單介紹使用gSOAP研發(fā)2.2.1.3中的AXIS服務(wù)器的客戶(hù)程式。

            下載gSOAP工具的代碼地址,當(dāng)前最新版本是2.7.8c版本:

            http://sourceforge.net/project/showfiles.php?group_id=52781

            解壓縮本地目錄,進(jìn)入bin目錄

            根據(jù)wsdl生成頭文檔方式有以下幾種:

            生成C++代碼

            $ wsdl2h -o testClient.h http://localhost:8080/axis/services/HelloService?wsdl

            生成C++代碼,不是用STL

            $ wsdl2h -s -o testClient.h http://localhost:8080/axis/services/HelloService?wsdl

            生成純C代碼

            $ wsdl2h -c  -o testClient.h http://localhost:8080/axis/services/HelloService?wsdl

            本例使用C++代碼(含STL)方式

            生成客戶(hù)端代碼,使用如下命令(不帶-C參數(shù)生成客戶(hù)端和服務(wù)器代碼)

            soapcpp2 -C –I..\import testClient.h

            打開(kāi)VC,創(chuàng)建一個(gè)Win32的控制臺(tái)程式soapClient"Project", Settings", select the "Link" tab (the project file needs to be selected in the file view) and add "wsock32.lib

            把剛剛生成的以下代碼添加到工程中去:

            soapStub.h soapH.h soapC.cpp soapClient.cpp soapClientLib.cpp

            main函數(shù)中寫(xiě)入代碼soapClient.cpp

            // soap.cpp : Defines the entry point for the console application.

            //

             

            #include "stdafx.h"

            #include "soapH.h"

            #include "HelloServiceSoapBinding.nsmap"

             

             

            int main(int argc, char* argv[])

            {

                     struct soap soap;

                     std::string a="STS Corp.";

                     int b=0;

                     std::string result;

              if (argc < 3)

              { fprintf(stderr, "Usage: string num\n");

                exit(0);

              }

              soap_init(&soap);

             

              a=argv[1];

              b = atoi(argv[2]);

              DWORD begin= GetTickCount();

              for (int i=0;i<1;i++)

              {

                     soap_call_ns1__sayHello(&soap, "http://10.41.25.70:8080/axis/services/HelloService", "", a, b, result);

               

                     if (soap.error)

                     {

                               soap_print_fault(&soap, stderr);

                               exit(1);

                     }

                     else

                printf("result = %s\n", result.c_str());

                     b++;

              }

              DWORD end= GetTickCount();

             

              printf("每秒處理%d個(gè)\n", 1*1000/(end-begin));

             

              soap_destroy(&soap);

              soap_end(&soap);

              soap_done(&soap);

              system("pause");

              return 0;

            }

            編譯完成后,直接以命令行方式運(yùn)行程式soapClient “STS Corp.” 9

            輸出結(jié)果為result = Hello:“STS~~~~~~~~~~square=0,配置循環(huán)控制變量能夠簡(jiǎn)單用于測(cè)試性能。

            代碼中使用soap_init2能夠配置http1.1消息頭的connection屬性為keep-alive,當(dāng)配置為keep-alive時(shí),每秒交互能夠達(dá)到360次以上,假如使用close方式,每秒交互大約200次以上。

            發(fā)出的請(qǐng)求消息如下:

            POST /axis/services/HelloService HTTP/1.1

            Host: 10.41.25.70:8080

            User-Agent: gSOAP/2.7

            Content-Type: text/xml; charset=utf-8

            Content-Length: 478

            Connection: close

            SOAPAction: ""

             

            <?xml version="1.0" encoding="UTF-8"?>

            <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://demo"><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><ns1:sayHello><in0>STS Corp.</in0><in1>9</in1></ns1:sayHello></SOAP-ENV:Body></SOAP-ENV:Envelope>

             

            響應(yīng)消息:

            HTTP/1.1 200 OK

            Server: Apache-Coyote/1.1

            Content-Type: text/xml;charset=utf-8

            Date: Tue, 29 Aug 2006 10:36:45 GMT

            Connection: close

             

            <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:sayHelloResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://demo"><sayHelloReturn xsi:type="xsd:string">Hello:STS Corp.~~~~~~~~~~square=81</sayHelloReturn></ns1:sayHelloResponse></soapenv:Body></soapenv:Envelope>

            1.1.1.3     gSOAP+VC研發(fā)服務(wù)器

            gSOAP是開(kāi)放的C/C++源碼的soap服務(wù)器實(shí)現(xiàn),能夠參考gSOAP包中的幫助文檔,本文檔略。

            posted on 2008-05-27 18:38 肥仔 閱讀(7975) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): 網(wǎng)絡(luò)編程

            評(píng)論

            # re: VC 的gSOAP例子  回復(fù)  更多評(píng)論   

            我的網(wǎng)站需要使用soap,學(xué)習(xí)了,博主,謝了。
            2012-04-17 17:18 | 萬(wàn)家購(gòu)物
            久久久黄色大片| 精品久久久久久99人妻| 999久久久国产精品| 国产亚洲色婷婷久久99精品| 中文字幕亚洲综合久久菠萝蜜| 久久免费观看视频| 久久成人精品| 久久影视综合亚洲| 人人狠狠综合久久亚洲| 久久婷婷人人澡人人| 亚洲国产日韩欧美久久| 日本加勒比久久精品| 日韩欧美亚洲综合久久影院Ds| 国内精品综合久久久40p| 国产精品久久久久久五月尺| 久久久精品国产| 人妻精品久久无码专区精东影业 | 97久久超碰成人精品网站| 无码精品久久久久久人妻中字| 久久婷婷国产麻豆91天堂| 久久e热在这里只有国产中文精品99 | 色综合久久天天综合| 日本免费一区二区久久人人澡 | 好久久免费视频高清| 久久成人国产精品一区二区| 国内精品久久久久久久久| 亚洲国产成人久久一区WWW| 久久久久高潮综合影院| 久久久青草久久久青草| 久久99亚洲综合精品首页| 久久99这里只有精品国产| 色婷婷综合久久久中文字幕| 久久精品国产只有精品2020| 欧美激情精品久久久久久久| 亚洲AV无一区二区三区久久| 久久99国产精品久久| 无码日韩人妻精品久久蜜桃| 久久―日本道色综合久久| 波多野结衣久久一区二区 | 18禁黄久久久AAA片| 色婷婷综合久久久久中文一区二区|