webservice hello

一、

// hello.h
int ns__hello(std::string name, std::string& greeting);

二、

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//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 

 

posted @   atom_lxh  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示