一、
// hello.h int ns__hello(std::string name, std::string& greeting);
二、
//helloclient.cpp #include "soapH.h" #include "ns.nsmap" #include <string> #include <iostream> using namespace std; int hello(struct soap *soap,std::string name,std::string& greeting) { int flag = -1; flag = soap_call_ns__hello(soap, "http://localhost:8080", "", name,greeting); return flag; } int main() { std::string name= "Luoxuehua"; std::string greeting; struct soap *soap = soap_new(); int flag = -1; for (int i = 0;i<50 ;i++) { std::string str = std::to_string(i*10); name.append(str.c_str()); flag = hello(soap,name,greeting); if (flag ==0) { printf("%s\n", greeting.c_str()); std::cout << "result:"<<greeting <<std::endl; } } soap_destroy(soap); soap_end(soap); soap_free(soap); return 0; }
三、
c++ -o helloclient helloclient.cpp soapC.cpp soapclient.cpp stdsoap2.cpp -lws2_32
四、
soapcpp2 -C hello.h soapcpp2 -S hello.h wsdl2h -o dd.h ns.wsdl
五
//helloserver.cpp #include "soapH.h" #include "ns.nsmap" #include <string> #include <iostream> int main() { struct soap *soap = soap_new(); SOAP_SOCKET m = soap_bind(soap, NULL, 8080, 1); if (soap_valid_socket(m)) { while (true) { SOAP_SOCKET s = soap_accept(soap); if (!soap_valid_socket(s)) break; soap_serve(soap); soap_destroy(soap); soap_end(soap); } } soap_print_fault(soap, stderr); soap_free(soap); } int ns__hello(struct soap *soap, std::string name, std::string& greeting) { printf("soap start name:%s\n",name.c_str()); greeting="Hello world:"; greeting.append(name.c_str()); return SOAP_OK; }
六
//编译 g++ -o helloserver helloserver.cpp soapC.cpp soapserver.cpp stdsoap2.cpp -lws2_32
标签:std,webservice,int,hello,cpp,include,soap From: https://www.cnblogs.com/luoxh-whn/p/18337055