首页 > 应用开发 > IT综合 > 编写SOAP的ANSI C客户程序示例
1. 准备工作
1.1 下载、展开gSOAP
1.2 设置环境变量
set GSOAP=Z:gsoap-2.7
1.3 编译soapcpp2.obj
cd %GSOAP%soapcpp2
cl -c stdsoap2.c
2. 编译SOAP客户程序
2.1 从WSDL生成C头文件(包括预编译注释)
#例:
%GSOAP%soapcpp2wsdl2h -c -o quote.h xmethods-delayed-quotes.wsdl
2.2 编译框架文件
#例:
%GSOAP%soapcpp2soapcpp2 -c quote.h
2.3 编写客户程序
#例:
#include "soapH.h" // obtain the generated stub
#include "net_x002exmethods_x002eservices_x002estockquote_x002eStockQuoteBinding.nsmap" // obtain the generated XML namespace mapping table for the Quote service (soapcpp2生成的nsmap文件)
int main(){
struct soap *soap = soap_new();
float quote;
if (soap_call_ns1__getQuote(soap, NULL, NULL, "IBM", "e) == SOAP_OK)
printf("Current IBM Stock Quote = %gn", quote);
else // an error occurred
soap_print_fault(soap, stderr); // display the SOAP fault on the stderr stream
return 0;
}
2.4 编译客户程序
cl -o test.exe -I%GSOAP%soapcpp2 test.c soapC.c soapClient.c ..stdsoap2.obj
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8883925/viewspace-899150/ ,如需转载,请注明出处,否则将追究法律责任。