免费注册 查看新帖 |

Chinaunix

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

[Linux] 求一个gsoap输出参数都为结构体的例子 [复制链接]

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

  1. //gsoap ns service name: JobService
  2. //gsoap ns service style: rpc
  3. //gsoap ns service namespace:-
  4. //gsoap ns service location: h t t p:-
  5. //gsoap ns service encoding: encoded
  6. //gsoap ns schema namespace: urn:JobService

  7. typedef char * xsd__string;
  8. typedef long   xsd__int;
  9. struct ns__personResponse{
  10. xsd__int age;
  11. xsd__string name;
  12. xsd__string address;
  13. };
  14. int ns__StructArray( xsd__string buf_in, struct ns__personResponse * buf_out );

  15. JobServiceserver.c

  16. #include "soapH.h"
  17. #include "JobService.nsmap"

  18. int ns__StructArray(struct soap *soap, xsd__string buf_in, struct ns__personResponse * buf_out )
  19. {
  20.   printf ( " inPut \n" ) ;
  21.   static struct ns__personResponse outStur ;
  22.   memset ( &outStur , 0 , sizeof ( outStur ) ) ;
  23.   buf_out = &outStur ;
  24.   outStur.name = (char *)soap_malloc( soap , 1024 ) ;
  25.   outStur.address = ( char * )soap_malloc( soap , 1024 ) ;

  26.   printf ( " inPut [%s] \n" , buf_in ) ;

  27.   strcpy ( outStur.name , "Juan.xu " ) ;
  28.   strcpy ( outStur.address , " HuBei Wuhan " ) ;

  29.   return SOAP_OK;
  30. }

  31. int main(int argc, char **argv)
  32. {
  33.         int m, s;               /* master and slave sockets */
  34.         struct soap SmsWBS_soap;

  35.         soap_init(&SmsWBS_soap);

  36.         soap_set_namespaces(&SmsWBS_soap, namespaces);

  37.         if (argc < 2)
  38.         {
  39.                 printf("usage: %s <server_port> \n", argv[0]);
  40.                 exit(1);
  41.         }
  42.         else
  43.         {
  44.                 m = soap_bind(&SmsWBS_soap, NULL, atoi(argv[1]), 100);
  45.                 if (m < 0)
  46.                 {
  47.                         soap_print_fault(&SmsWBS_soap, stderr);
  48.                         exit(-1);
  49.                 }

  50.                 fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
  51.                 for (;;)
  52.                 {
  53.                         s = soap_accept(&SmsWBS_soap);

  54.                         if (s < 0)
  55.                         {
  56.                                 soap_print_fault(&SmsWBS_soap, stderr);
  57.                                 exit(-1);
  58.                         }

  59.                         fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);
  60.                         soap_serve(&SmsWBS_soap);
  61.                         soap_end(&SmsWBS_soap);
  62.                 }

  63.        }

  64.         return 0;
  65. }

  66. JobServicetest.c

  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include "soapStub.h"           
  70. #include "JobService.nsmap"
  71. #include <string.h>
  72.         
  73. const char server[] = "localhost:9000";
  74. int main(int argc, char **argv)
  75. {
  76.   struct soap soap;
  77.   char buf[1024]="Tell me the job status!";
  78.   struct ns__personResponse result;
  79.   if (argc<1)   
  80.   {     
  81.     fprintf(stderr, "Usage: jobOptionfile n");
  82.     exit(0);
  83.   }            
  84.                
  85.   soap_init(&soap);
  86.                         
  87.   printf ( " RES : [%s]\n" , buf ) ;
  88.                
  89.   result.name = (char *)soap_malloc( &soap , 1024 ) ;
  90.   result.address = ( char * )soap_malloc( &soap , 1024 ) ;

  91.   soap_call_ns__StructArray(&soap, server,"", buf, &result);
  92.                
  93.   if (soap.error)  {   
  94.     soap_print_fault(&soap, stderr);
  95.     printf("soap wrong: %d, n please inform the administrator!n",soap.error);
  96.     exit(1);            
  97.   }                             
  98.                                 
  99.   printf ( " REQ : \n" ) ;
  100.   printf ( " REQ : name[%s] \n" , result.name ) ;
  101.   printf ( " REQ : address[%s] \n" , result.address ) ;
  102.                         
  103.   soap_destroy(&soap);  
  104.   soap_end(&soap);
  105.   return 1;
  106. }      

  107. Makefile

  108. GSOAP_ROOT=/usr/local/gSOAP
  109. WSNAME0=soap
  110. WSNAME=JobService
  111. CC=g++ -g -DWITH_NONAMESPACES
  112. INCLUDE=-I $(GSOAP_ROOT)/include
  113. SERVER_OBJS=$(WSNAME0)C.o $(WSNAME0)Server.o stdsoap2.o
  114. CLIENT_OBJS=$(GSOAP_ROOT)/env/envC.o $(WSNAME0)ClientLib.o stdsoap2.o
  115. ALL_OBJS=${WSNAME}server.o $(WSNAME0)C.o $(WSNAME0)Server.o ${WSNAME}test.o $(WSNAME0)ClientLib.o
  116. GSOAP_SRC=/usr/local/src/gsoap-2.8/gsoap
  117.   
  118. all:server
  119.   
  120. ${WSNAME}.wsdl:${WSNAME}.h
  121.         $(GSOAP_ROOT)/bin/soapcpp2 -b -c $(GSOAP_ROOT)/import ${WSNAME}.h
  122.    
  123. stdsoap2.o:$(GSOAP_SRC)/stdsoap2.c
  124.         $(CC) -c $? $(INCLUDE)
  125.                
  126. $(ALL_OBJS):%.o:%.c
  127.         $(CC) -c $? $(INCLUDE)
  128.   
  129. server:Makefile ${WSNAME}.wsdl ${WSNAME}server.o $(SERVER_OBJS)
  130.         $(CC) ${WSNAME}server.o $(SERVER_OBJS) -o ${WSNAME}server
  131.   
  132. client:Makefile ${WSNAME}.wsdl ${WSNAME}test.c $(ALL_OBJS) stdsoap2.o
  133.         $(CC) ${WSNAME}test.o $(CLIENT_OBJS) -o ${WSNAME}test
  134.                
  135. clean:
  136.         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

  137.    
复制代码

论坛徽章:
0
2 [报告]
发表于 2015-04-15 10:42 |只看该作者
在线等,谢谢!

论坛徽章:
0
3 [报告]
发表于 2015-04-15 14:25 |只看该作者
求高手支持一下

论坛徽章:
0
4 [报告]
发表于 2015-04-24 23:38 |只看该作者
没有人回我呀!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP