2012-02-01 167 views
4

我想爲Windows上的項目實現Web服務客戶端。 我想獲得Web服務信息,肥皂請求和肥皂響應。 我需要一個C++庫,我可以用於這些目的(而不是wsdlpull)。C++的Web服務客戶端庫

要求

  • 應該是一個C++庫
  • 可用於訪問任何SOAP的Web服務(這樣我就可以通過URL,Web服務名稱,Web服務方法和所有參數作爲參數傳遞給函數調用)
  • 可以查詢web服務它的WSDL,並返回我的可用方法名,方法參數和數據類型
  • 簡單doucmentation

更具體:圖書館應該有簡單的調用像這樣來的Web服務信息

invoker.getOperations(operations); 

outputXml += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; 
outputXml += "<webService"; 
outputXml += " name=\"" + GetServiceName(&invoker) + "\""; 
outputXml += ">\n"; 
outputXml += "\t<webMethods>\n"; 

感謝。

回答

7

C/C++ Web服務的行業標準是gsoap。 http://www.cs.fsu.edu/~engelen/soap.html

提供使用wsdl2h將XML Schema映射到C/C++。它有很好的文檔和很多樣品。 Doc也可以找到online。在許多操作系統,您可以輕鬆地將您的代碼(Linux操作系統,windows等)

Simpe例如通過Web服務增加數(調用代碼)

#include "soapH.h" 
#include "calc.nsmap" 
main() 
{ 
    struct soap *soap = soap_new(); 
    double result; 
    if (soap_call_ns__add(soap, 1.0, 2.0, &result) == SOAP_OK) 
     printf("The sum of 1.0 and 2.0 is %lg\n", result); 
    else 
     soap_print_fault(soap, stderr); 
    soap_end(soap); 
    soap_free(soap); 
} 

與你兩個步驟做gSOAP的工作

  1. 首先創建從WSDL存​​根(如WSDL2Java的)
  2. 然後調用存根與你的對象

如果您想創建您的服務(作爲服務器,不僅是客戶端代碼),也是出色的框架