Linux的soap服务怎么开启,Linux下用gSOAP开发Web Service服务端和客户端程序(二)

C++版本的程序:

(1)头文件不变,还是SmsWBS.h

(2)Makefile文件:

GSOAP_ROOT=/usr/local/gSOAP

WSNAME0=soap

WSNAME=SmsWBS

CC=g++ -g -DWITH_NONAMESPACES

INCLUDE=-I $(GSOAP_ROOT)/include

SERVER_OBJS=$(WSNAME0)C.o $(WSNAME0)$(WSNAME)Service.o stdsoap2.o

CLIENT_OBJS=$(WSNAME0)$(WSNAME)Proxy.o $(WSNAME0)C.o stdsoap2.o

ALL_OBJS=${WSNAME}server.o $(WSNAME0)C.o $(WSNAME0)$(WSNAME)Service.o $(WSNAME0)$(WSNAME)Proxy.o ${WSNAME}test.o

#GSOAP_SRC=/usr/local/gsoap-2.7/gsoap

all:server

${WSNAME}.wsdl:${WSNAME}.h

$(GSOAP_ROOT)/bin/soapcpp2 -i $(GSOAP_ROOT)/import ${WSNAME}.h

stdsoap2.o:$(GSOAP_ROOT)/src/stdsoap2.cpp

$(CC) -c $? $(INCLUDE)

$(ALL_OBJS):%.o:%.cpp

$(CC) -c $? $(INCLUDE)

server:Makefile ${WSNAME}.wsdl ${WSNAME}server.o $(SERVER_OBJS)

$(CC) ${WSNAME}server.o $(SERVER_OBJS) -o ${WSNAME}server

client:Makefile ${WSNAME}.wsdl ${WSNAME}test.cpp $(ALL_OBJS) stdsoap2.o

$(CC) ${WSNAME}test.o $(CLIENT_OBJS) -o ${WSNAME}test

clean:

rm -f *.o *.xml *.a *.wsdl *.nsmap $(WSNAME0)H.h $(WSNAME0)C.cpp $(WSNAME0)Server.cpp  $(WSNAME0)Stub.* $(WSNAME0)$(WSNAME)S

ervice.* $(WSNAME0)$(WSNAME)Proxy.* $(WSNAME0)$(WSNAME)Object.* $(WSNAME0)ServerLib.cpp $(WSNAME0)ClientLib.cpp $(WSNAME)server ns.x

sd $(WSNAME)test

(3)服务端程序SmsWBSserver.cpp:

#include "soapSmsWBSService.h"

#include "SmsWBS.nsmap"

int main(int argc, char **argv)

{

SmsWBSService sms;

if (argc < 2)

sms.serve();       /* serve as CGI application */

else

{

int port = atoi(argv[1]);

if (!port)

{

fprintf(stderr, "Usage: SmsWBSserver++ \n");

exit(0);

}

/* run iterative server on port until fatal error */

if (sms.run(port))

{

sms.soap_stream_fault(std::cerr);

exit(-1);

}

}

return 0;

}

int SmsWBSService::add(int num1, int num2, int *sum)

{

*sum = num1 + num2;

return SOAP_OK;

}

(4)客户端程序SmsWBStest.cpp:

#include

#include

#include "soapSmsWBSProxy.h"

#include "SmsWBS.nsmap"

int main(int argc, char **argv)

{

int result = -1;

char* server="http://localhost:9000";

int num1 = 0;

int num2 = 0;

int sum = 0;

if( argc < 3 )

{

printf("usage: %s num1 num2 \n", argv[0]);

exit(0);

}

num1 = atoi(argv[1]);

num2 = atoi(argv[2]);

SmsWBSProxy  sms;

result = sms.add(num1, num2, &sum);

if (result != 0)

{

printf("soap err, errcode = %d \n", result);

}

else

{

printf("%d + %d = %d \n", num1, num2, sum);

}

return 0;

}

(5)编译运行,与C版本类似,只是服务端运行时没有提示信息

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值