免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3397 | 回复: 3
打印 上一主题 下一主题

[C] 求一个linux下可以运行的传递结构体参数gsoap例子 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-04-15 14:51 |只看该作者 |倒序浏览
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

                        

论坛徽章:
15
射手座
日期:2014-11-29 19:22:4915-16赛季CBA联赛之青岛
日期:2017-11-17 13:20:09黑曼巴
日期:2017-07-13 19:13:4715-16赛季CBA联赛之四川
日期:2017-02-07 21:08:572015年亚冠纪念徽章
日期:2015-11-06 12:31:58每日论坛发贴之星
日期:2015-08-04 06:20:00程序设计版块每日发帖之星
日期:2015-08-04 06:20:00程序设计版块每日发帖之星
日期:2015-07-12 22:20:002015亚冠之浦和红钻
日期:2015-07-08 10:10:132015亚冠之大阪钢巴
日期:2015-06-29 11:21:122015亚冠之广州恒大
日期:2015-05-22 21:55:412015年亚洲杯之伊朗
日期:2015-04-10 16:28:25
2 [报告]
发表于 2015-04-17 14:41 |只看该作者
rxu195 发表于 2015-04-15 14:51
正在学习gsoap,想做一个C语言用远程调用输入输出参数都为结构体的例子。 找遍了百度有些例子。但是在linux ...

传送结构体需要序列化。你选择一种序列化格式:XML,JSON,html。。。。。。。。。

论坛徽章:
0
3 [报告]
发表于 2015-04-24 23:39 |只看该作者
如何序列化呢?!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP