论坛徽章: 0
5 可用积分
正在学习gsoap,想做一个C语言用远程调用输入输出参数都为结构体的例子。 找遍了百度有些例子。但是在linux环境下不是是编译报错,就是运行core dump,求高手发个可以用的例子,谢谢!
或者帮忙看看我写的程序有什么问题,谢谢!
以下例子,客户端就core了,不知道什么问题,求解答。
环境:
gsoap-2.8
Linux xxxx 3.8.13-44.1.1.el6uek.x86_64 #2 SMP Wed Sep 10 06:10:25 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux
JobService.h
//gsoap ns service name: JobService
//gsoap ns service style: rpc
//gsoap ns service namespace: h t t p :/ / 38.19.201.10:9000 / JobService.wsdl
//gsoap ns service location: h t t p : // 38.19.201.10:9000
//gsoap ns service encoding: encoded
//gsoap ns schema namespace: urn:JobService
typedef char * xsd__string;
typedef long xsd__int;
struct ns__personResponse{
xsd__int age;
xsd__string name;
xsd__string address;
};
int ns__StructArray( xsd__string buf_in, struct ns__personResponse * buf_out );
JobServiceserver.c
#include "soapH.h"
#include "JobService.nsmap"
int ns__StructArray(struct soap *soap, xsd__string buf_in, struct ns__personResponse * buf_out )
{
printf ( " inPut \n" ) ;
static struct ns__personResponse outStur ;
memset ( &outStur , 0 , sizeof ( outStur ) ) ;
buf_out = &outStur ;
outStur.name = (char *)soap_malloc( soap , 1024 ) ;
outStur.address = ( char * )soap_malloc( soap , 1024 ) ;
printf ( " inPut [%s] \n" , buf_in ) ;
strcpy ( outStur.name , "Juan.xu " ) ;
strcpy ( outStur.address , " HuBei Wuhan " ) ;
return SOAP_OK;
}
int main(int argc, char **argv)
{
int m, s; /* master and slave sockets */
struct soap SmsWBS_soap;
soap_init(&SmsWBS_soap);
soap_set_namespaces(&SmsWBS_soap, namespaces);
if (argc < 2)
{
printf("usage: %s <server_port> \n", argv[0]);
exit(1);
}
else
{
m = soap_bind(&SmsWBS_soap, NULL, atoi(argv[1]), 100);
if (m < 0)
{
soap_print_fault(&SmsWBS_soap, stderr);
exit(-1);
}
fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
for (;
{
s = soap_accept(&SmsWBS_soap);
if (s < 0)
{
soap_print_fault(&SmsWBS_soap, stderr);
exit(-1);
}
fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);
soap_serve(&SmsWBS_soap);
soap_end(&SmsWBS_soap);
}
}
return 0;
}
JobServicetest.c
#include <stdio.h>
#include <stdlib.h>
#include "soapStub.h"
#include "JobService.nsmap"
#include <string.h>
const char server[] = " h t t p : // localhost : 9000 ";
int main(int argc, char **argv)
{
struct soap soap;
char buf[1024]="Tell me the job status!";
struct ns__personResponse result;
if (argc<1)
{
fprintf(stderr, "Usage: jobOptionfile n" ;
exit(0);
}
soap_init(&soap);
printf ( " RES : [%s]\n" , buf ) ;
result.name = (char *)soap_malloc( &soap , 1024 ) ;
result.address = ( char * )soap_malloc( &soap , 1024 ) ;
soap_call_ns__StructArray(&soap, server,"", buf, &result);
if (soap.error) {
soap_print_fault(&soap, stderr);
printf("soap wrong: %d, n please inform the administrator!n",soap.error);
exit(1);
}
printf ( " REQ : \n" ) ;
printf ( " REQ : name[%s] \n" , result.name ) ;
printf ( " REQ : address[%s] \n" , result.address ) ;
soap_destroy(&soap);
soap_end(&soap);
return 1;
}
Makefile
GSOAP_ROOT=/usr/local/gSOAP
WSNAME0=soap
WSNAME=JobService
CC=g++ -g -DWITH_NONAMESPACES
INCLUDE=-I $(GSOAP_ROOT)/include
SERVER_OBJS=$(WSNAME0)C.o $(WSNAME0)Server.o stdsoap2.o
CLIENT_OBJS=$(GSOAP_ROOT)/env/envC.o $(WSNAME0)ClientLib.o stdsoap2.o
ALL_OBJS=${WSNAME}server.o $(WSNAME0)C.o $(WSNAME0)Server.o ${WSNAME}test.o $(WSNAME0)ClientLib.o
GSOAP_SRC=/usr/local/src/gsoap-2.8/gsoap
all:server
${WSNAME}.wsdl {WSNAME}.h
$(GSOAP_ROOT)/bin/soapcpp2 -b -c $(GSOAP_ROOT)/import ${WSNAME}.h
stdsoap2.o (GSOAP_SRC)/stdsoap2.c
$(CC) -c $? $(INCLUDE)
$(ALL_OBJS):%.o:%.c
$(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.c $(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.c $(WSNAME0)Server.c $(WSNAME0)Client.c $(WSNAME0)Stub.* $(WSNAME)$(WSNAME)Proxy.* $(WSNAME)$(WSNAME)Object.* $(WSNAME0)ServerLib.c $(WSNAME0)ClientLib.c $(WSNAME)server ns.xsd $(WSNAME)test
我来回答