linux gsoap服务端,gsoap linux下服务器端代码生成与测试

二、解压压缩包。ios

三、进入cd gSoap/gsoap-2.8/gsoap/bin/linux386函数

四、建立一个头文件serverTest.h测试

//gsoap ns service name: calc

//gsoap ns service style: rpc

//gsoap ns service encoding: encoded

//gsoap ns service namespace: http://127.0.0.1:8089/calc.wsdl

//gsoap ns service location: http://127.0.0.1:8089/cal

//gsoap ns schema  namespace:    urn:calc

int ns__hello(char *p, char *result);

int ns__add(double a, double b, double *result);

int ns__sub(double a, double b, double *result);

int ns__mul(double a, double b, double *result);

int ns__div(double a, double b, double *result);

int ns__pow(double a, double b, double *result);spa

五、./soapcpp2 -i serverTest.h.net

生成须要的文件code

六、中calc.wsdl、soapC.cpp、soapStub.h、soapcalcService.h、stdsoap2.h、 calc.nsmap、serverTest.h、soapH.h  、  soapcalcService.cpp、 stdsoap2.cpp 是须要的文件。server

七、建立main.cpp文件xml

#include "iostream"

#include "soapcalcService.h"

#include "stdafx.h"

#include "calc.nsmap"blog

#include

using namespace std;

//º??ª

int  http_get(struct   soap   *soap)

{

FILE*fd = NULL;

fd = fopen("./calc.wsdl", "rb"); //open WSDL file to copy

if (!fd)

{

return 404; //return HTTP not found error

}

soap->http_content = "text/xml";  //HTTP header with text /xml content

soap_response(soap, SOAP_FILE);

for (;;)

{

size_t r = fread(soap->tmpbuf, 1, sizeof(soap->tmpbuf), fd);

if (!r)

{

break;

}

if (soap_send_raw(soap, soap->tmpbuf, r))

{

break; //cannot send, but little we can do about that

}

}

fclose(fd);

soap_end_send(soap);

return SOAP_OK;

}

int main(int argc, char *argv[])

{

calcService cal;

cal.fget = http_get;

while (1)

{

if (cal.run(8089))

{

cal.soap_stream_fault(std::cerr);

}

}

return 0;

}

八、编写makefile

OBJ_NS := calc

GSOAP_ROOT := /home/likaiqiang/test/gSoap/gsoap-2.8/gsoap/bin/linux386/server/testCore

INCLUDE := -I$(GSOAP_ROOT)

#GCC := g++

CXX := arm-linux-gnueabihf-g++

CFLAGS += -w

CXXFLAGS += -w

OBJ_SERVER := stdafx.o soapC.o stdsoap2.o soap$(OBJ_NS)Service.o

server: $(OBJ_SERVER)

$(CXX) $(CXXFLAGS) $(INCLUDE) $^ -o $@

clean:

rm -f server client *.o

九、编译运行,出错提示没有实现头文件里面的五个函数的实现

soapcalcService.o:(.rodata._ZTV11calcService[_ZTV11calcService]+0xc0): undefined reference to `calcService::hello(char*, char*)'

soapcalcService.o:(.rodata._ZTV11calcService[_ZTV11calcService]+0xc8): undefined reference to `calcService::add(double, double, double*)'

soapcalcService.o:(.rodata._ZTV11calcService[_ZTV11calcService]+0xd0): undefined reference to `calcService::sub(double, double, double*)'

soapcalcService.o:(.rodata._ZTV11calcService[_ZTV11calcService]+0xd8): undefined reference to `calcService::mul(double, double, double*)'

soapcalcService.o:(.rodata._ZTV11calcService[_ZTV11calcService]+0xe0): undefined reference to `calcService::div(double, double, double*)'

soapcalcService.o:(.rodata._ZTV11calcService[_ZTV11calcService]+0xe8): undefined reference to `calcService::pow(double, double, double*)'

collect2: error: ld returned 1 exit status

make: *** [server] Error 1

十、在soapcalcService.cpp文件中实现相关函数

int calcService::hello(char *p, char *result)

{

if (NULL == p || NULL == result)

{

printf("Error:The third argument should not be NULL!\n");

return SOAP_ERR;

}

else

{

printf("recv :%s\n",p);

memcpy(result,"hello world",16);

return SOAP_OK;

}

return SOAP_OK;

}

int calcService::add(double num1, double num2, double* result)

{

if (NULL == result)

{

printf("Error:The third argument should not be NULL!\n");

return SOAP_ERR;

}

else

{

(*result) = num1 + num2;

return SOAP_OK;

}

return SOAP_OK;

}

/*减法的具体实现*/

int calcService::sub(double num1, double num2, double* result)

{

if (NULL == result)

{

printf("Error:The third argument should not be NULL!\n");

return SOAP_ERR;

}

else

{

(*result) = num1 - num2;

return SOAP_OK;

}

return SOAP_OK;

}

/*乘法的具体实现*/

int calcService::mul(double num1, double num2, double* result)

{

if (NULL == result)

{

printf("Error:The third argument should not be NULL!\n");

return SOAP_ERR;

}

else

{

(*result) = num1 * num2;

return SOAP_OK;

}

return SOAP_OK;

}

/*除法的具体实现*/

int calcService::div(double num1, double num2, double* result)

{

if (NULL == result || 0 == num2)

{

return soap_senderfault("Square root of negative value", "I can only compute the square root of a non-negative value");

return SOAP_ERR;

}

else

{

(*result) = num1 / num2;

return SOAP_OK;

}

return SOAP_OK;

}

int calcService::pow(double num1, double num2, double* result)

{

if (NULL == result || 0 == num2)

{

printf("Error:The second argument is 0 or The third argument is NULL!\n");

return SOAP_ERR;

}

else

{

(*result) = num1 / num2;

return SOAP_OK;

}

return SOAP_OK;

}

十一、运行./server

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
gsoap-2.8源码,基于服务器客户的实例,带自动生成服务客户代码的批处理程序,及如何使用。带自己学习参考的教程; 0.解压附件,soapInterface.bat所在路径不得含中文 空格 1.新建头文件 取soapInterface.bat文件的同名:soapInterface.h 文件内编写接口,具体说明看附件参考的教程 //gsoap ns service name: gservice //gsoap ns service style: rpc int ns__add(int num1, int num2, int* result ); int ns__sub(int num1, int num2, int* result ); int ns__mult( int num1, int num2, int *result); int ns__divid( int num1, int num2, int *result); 2.从附件内gsoap-2.8包中搜索复制stdsoap2.h,stdsoap2.cpp,soapcpp2.exe, 存放于soapInterface.bat同级目录 3.双击soapInterface.bat运行。生成gClientSoap,gServerSoap两个文件夹,分别复制到服务器工程与客户工程中使用 4.gClientSoap,gServerSoap两个文件夹内用到的文件功能说明,更多参考附件教程 1)soapC.cpp , soapH.h//soap的序列和反序列代码,它已经包含了soapStub.h 2)soapServer.c ppsoapServerLib.cpp //服务器代码(纯C代码是soapServer.c soapServerLib.c ),soapServerLib.cpp文件则只是简单地包含soapServer.cpp和soapC.cpp 3)soapClient.cpp soapClientLib.cpp//客户代码(纯C代码是soapClient.csoapClientLib.c ),soapClientLib.cpp文件则只是简单地包含soapClient.cpp和soapC.cpp 4) soapStub.h // soap的存根文件,定义了我们编写的头文件里对应的远程调用模型 5) add.nsmap //XML服务命名空间 6)服务器要载入的文件有:soapServer.cpp,soapC.cpp,stdsoap2.cpp; 要包含的文件有:gservice.nsmap,soapH.h; 客户要输入的文件有: soapClient.cpp,soapC.cpp,stdsoap2.cpp; 要包含的文件有:gservice.nsmap,soapH.h
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值