user-0 提问: 用gsoap返回结构体数组遇到的问题？怎么只返回了一个结构？ 

回复:
user: user-1
content: LZ，我也遇到了同样的问题想问下你怎么解决的，你后面贴的代码的客户端和服务端函数和输出参数的数据结构都不一致啊

user: user-0
content: 问题已解决，分享一下。 /**********测试开始**********/ struct ns__card { xsd__string holdername; xsd__string value; };  struct ns__cardList { struct ns__card *__ptr; int __size; };  int ns__testfun(xsd__string bufin,struct ns__cardList *list);  /*服务端程序*/ int ns__testfun(struct soap *soap,xsd__string bufin,struct ns__cardList  *list) { printf("in=[%s]\n",bufin); list->__size =2;   list->__ptr = soap_malloc(soap,list->__size*sizeof(struct ns__card));  int i=0; for(i=0;i<list->__size;i++) { if (i==0) { (list->__ptr+i)->holdername = soap_strdup(soap,"zhangsan"); (list->__ptr+i)->value= soap_strdup(soap,"123"); } else { (list->__ptr+i)->holdername = soap_strdup(soap,"lisi"); (list->__ptr+i)->value= soap_strdup(soap,"789"); } }  for(i=0;i<list->__size;i++) { printf("name=[%s]\n",(list->__ptr+i)->holdername); printf("\n"); } return SOAP_OK; }  /*客户端程序*/ printf("hello\n"); struct ns2__testfunResponse rest; soap_call_ns2__testfun( &soap, server, "","abc" , &rest); printf("size=[%d]\n",rest.list->__sizeitem); int t; for(t=0;t<rest.list->__sizeitem;t++) { //printf("name=[%s]\n",rest.list->item->holdername); printf("name=[%s]\n",(rest.list->item+t)->holdername); printf("name=[%s]\n",(rest.list->item+t)->value); } printf("ok\n"); };

user: user-0
content: 还没有人回答吗，再等等

user: user-0
content: to u012061345: 服务端写入后，可正常读出。

user: user-2
content: 服务端写进去以后，再读出来看看，有问题吗？

user: user-0
content: 谁有这种例子啊 给出来看看

user: user-0
content: 引用 9 楼 user-3 的回复:int ns__nsGetAccountBankCardList(struct soap *soap,xsd__string accountId,struct ns__GetAccountBankCardListResponse *response) {     response->__size=2;     response->cardList= (struct ns__BankCard **)soap_malloc(soap,sizeof(struct ns__BankCard *)); for(i=0;i<response->__size;i++) {     response->cardList[i]=(struct ns__BankCard *)soap_malloc(soap,sizeof(struct ns__BankCard ));      response->cardList[i])->cardType=CREDIT_CARD;     response->cardList[i])->cardholderName = (char *)soap_malloc(soap,32);     response->cardList[i])->cardholderName = soap_strdup(soap,"zhangsan");  }      for(i=0;i<response->__size;i++)     {            //printf("%d\n",(*response->cardList[i]).cardType);         printf("%s\n",(*response->cardList[i]).cardholderName);         printf("\n");     }     return SOAP_OK; } 此段代码主要改动是在(struct ns__BankCard **)里作了强制类型转换， 这样也不能得到正确结果

user: user-3
content: int ns__nsGetAccountBankCardList(struct soap *soap,xsd__string accountId,struct ns__GetAccountBankCardListResponse *response) {     response->__size=2;     response->cardList= (struct ns__BankCard **)soap_malloc(soap,sizeof(struct ns__BankCard *)); for(i=0;i<response->__size;i++) {     response->cardList[i]=(struct ns__BankCard *)soap_malloc(soap,sizeof(struct ns__BankCard ));      response->cardList[i])->cardType=CREDIT_CARD;     response->cardList[i])->cardholderName = (char *)soap_malloc(soap,32);     response->cardList[i])->cardholderName = soap_strdup(soap,"zhangsan");  }      for(i=0;i<response->__size;i++)     {            //printf("%d\n",(*response->cardList[i]).cardType);         printf("%s\n",(*response->cardList[i]).cardholderName);         printf("\n");     }     return SOAP_OK; }

user: user-0
content: 引用 6 楼 user-3 的回复:好像是这样的  struct ns__GetAccountBankCardListResponse {   xsd__int __size；     struct ns__BankCard **cardList;  }; 试过这种方式，这种方式客户端输出只能得到__size

user: user-0
content: 我再贴一次服务端代码，现在是这个样子。客户端还是只获取了一个 int ns__nsGetAccountBankCardList(struct soap *soap,xsd__string accountId,struct ns__GetAccountBankCardListResponse *response) {     response->__size=2;     response->cardList= soap_malloc(soap,(response->__size)*sizeof(struct ns__BankCard *));      response->cardList[0]=(struct ns__BankCard *)soap_malloc(soap,sizeof(struct ns__BankCard ));      (*response->cardList[0]).cardType=CREDIT_CARD;     (*response->cardList[0]).cardholderName = (char *)soap_malloc(soap,32);     (*response->cardList[0]).cardholderName = soap_strdup(soap,"zhangsan");      response->cardList[1]=(struct ns__BankCard *)soap_malloc(soap,sizeof(struct ns__BankCard ));      (*response->cardList[1]).cardType=PREPAID_CARD;//DEBIT_CARD;     (*response->cardList[1]).cardholderName = (char *)soap_malloc(soap,32);     //strcpy((*response->cardList[1]).cardholderName,"lisi");     (*response->cardList[1]).cardholderName = soap_strdup(soap,"lisi");      for(i=0;i<response->__size;i++)     {            //printf("%d\n",(*response->cardList[i]).cardType);         printf("%s\n",(*response->cardList[i]).cardholderName);         printf("\n");     }     return SOAP_OK; }

user: user-3
content: 好像是这样的  struct ns__GetAccountBankCardListResponse {   xsd__int __size；     struct ns__BankCard **cardList;  };

user: user-0
content: 引用 4 楼 user-3 的回复:使用soap_malloc替换malloc,soap_malloc的内存soap_destory会给你释放的 现在已经把malloc改为soap_malloc了，结果还是一样，只能得到第一个结构。问题出在哪了？

user: user-3
content: 使用soap_malloc替换malloc,soap_malloc的内存soap_destory会给你释放的