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

            文章均收錄自他人博客,但不喜標題前加-[轉貼],因其丑陋,見諒!~
            隨筆 - 1469, 文章 - 0, 評論 - 661, 引用 - 0
            數據加載中……

            VC 的gSOAP例子

            1.1.1   gSOAP

            1.1.1.1     簡介

            gSOAP編譯工具提供了一個SOAP/XML 關于C/C++ 語言的實現,從而讓C/C++語言研發web服務或客戶端程式的工作變得輕松了很多。絕大多數的C++web服務工具包提供一組API函數類庫來處理特定的SOAP數據結構,這樣就使得用戶必須改變程式結構來適應相關的類庫。和之相反,gSOAP利用編譯器技術提供了一組透明化的SOAP API,并將和研發無關的SOAP實現細節相關的內容對用戶隱藏起來。gSOAP的編譯器能夠自動的將用戶定義的本地化的CC++數據類型轉變為符合XML語法的數據結構,反之亦然。這樣,只用一組簡單的API就將用戶從SOAP細節實現工作中解脫了出來,能夠專注和應用程式邏輯的實現工作了。gSOAP編譯器能夠集成C/C++Fortran代碼(通過一個FortranC的接口),嵌入式系統,其他SOAP程式提供的實時軟件的資源和信息;能夠跨越多個操作系統,語言環境連同在防火墻后的不同組織。

                  gSOAP使編寫web服務的工作最小化了。gSOAP編譯器生成SOAP的代碼來序列化或反序列化C/C++的數據結構。gSOAP包含一個WSDL生成器,用他來為您的web服務生成web服務的解釋。gSOAP的解釋器及導入器能夠使用戶無需分析web服務的細節就能夠實現一個客戶端或服務端程式。

            1.1.1.2     gSOAP+VC研發客戶端

            gSOAP是開放的C/C++源碼的soap服務器實現,本章節簡單介紹使用gSOAP研發2.2.1.3中的AXIS服務器的客戶程式。

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

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

            解壓縮本地目錄,進入bin目錄

            根據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)方式

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

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

            打開VC,創建一個Win32的控制臺程式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函數中寫入代碼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\n", 1*1000/(end-begin));

             

              soap_destroy(&soap);

              soap_end(&soap);

              soap_done(&soap);

              system("pause");

              return 0;

            }

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

            輸出結果為result = Hello:“STS~~~~~~~~~~square=0,配置循環控制變量能夠簡單用于測試性能。

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

            發出的請求消息如下:

            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>

             

            響應消息:

            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研發服務器

            gSOAP是開放的C/C++源碼的soap服務器實現,能夠參考gSOAP包中的幫助文檔,本文檔略。

            posted on 2008-05-27 18:38 肥仔 閱讀(7986) 評論(1)  編輯 收藏 引用 所屬分類: 網絡編程

            評論

            # re: VC 的gSOAP例子  回復  更多評論   

            我的網站需要使用soap,學習了,博主,謝了。
            2012-04-17 17:18 | 萬家購物
            伊人久久大香线蕉亚洲五月天 | 久久天天躁狠狠躁夜夜躁2O2O | 国产69精品久久久久777| 成人久久精品一区二区三区| 91精品国产综合久久四虎久久无码一级 | 色天使久久综合网天天 | 思思久久99热免费精品6| 天天做夜夜做久久做狠狠| 久久精品国产亚洲AV忘忧草18| 久久亚洲美女精品国产精品| 亚洲嫩草影院久久精品| 99久久99久久精品国产片果冻| 91精品免费久久久久久久久| 亚洲欧洲日产国码无码久久99| 久久99精品久久久久久噜噜| avtt天堂网久久精品| 国产亚州精品女人久久久久久 | 久久久久亚洲AV成人网人人网站| 99久久中文字幕| 久久久亚洲裙底偷窥综合| 夜夜亚洲天天久久| 色婷婷久久综合中文久久蜜桃av| 久久久久亚洲AV无码专区桃色| 99久久婷婷免费国产综合精品| 亚洲精品乱码久久久久久按摩 | 亚洲成色WWW久久网站| 久久男人AV资源网站| 伊人热人久久中文字幕| 97久久香蕉国产线看观看| 亚洲AV无码成人网站久久精品大| 亚洲欧美久久久久9999| 国产精品内射久久久久欢欢| 色综合久久中文综合网| 青青国产成人久久91网| 婷婷综合久久狠狠色99h| 91精品国产9l久久久久| 精品人妻久久久久久888| 天天躁日日躁狠狠久久| 久久天天躁狠狠躁夜夜96流白浆| 一本色综合网久久| 色欲av伊人久久大香线蕉影院|