- 论坛徽章:
- 0
|
接口要求实现输入一个查询条件,返回一组结构,类似于查询明细。这样想来是要返回结构体数组的。
现在的问题是我在客户端测试时只能得到数组个数 和 第一个结构的内容,是哪里出错了呢?是服务端的实现有问题 还是 客户端取值有问题啊?
这个问题已经困扰我几天了,有哪位知道给指点下啊,代码如下:
/**服务端接口定义如下**/
struct ns__BankCard
{
xsd__string cardholderName;
xsd__string nationalId;
};
struct ns__GetAccountBankCardListResponse
{
struct ns__BankCard **cardList;
xsd__int __size;
};
int ns__nsGetAccountBankCardList(xsd__string accountId,struct ns__GetAccountBankCardListResponse *response);
/**我是这样实现接口函数的,有问题吗**/
int ns__nsGetAccountBankCardList(struct soap *soap,xsd__string accountId,struct ns__GetAccountBankCardListResponse *response)
{
response->__size=2;
response->cardList= malloc((response->__size+1)*sizeof(struct ns__BankCard *));
//response->cardList= malloc((response->__size+1)*sizeof(*response->cardList));
response->cardList[0]=(struct ns__BankCard *)malloc(sizeof(struct ns__BankCard ));
(*response->cardList[0]).cardholderName = (char *)malloc(32);
strcpy((*response->cardList[0]).cardholderName,"zhangsan");
response->cardList[1]=(struct ns__BankCard *)malloc(sizeof(struct ns__BankCard ));
(*response->cardList[1]).cardholderName = (char *)malloc(32);
strcpy((*response->cardList[1]).cardholderName,"lisi");
return SOAP_OK;
}
/*下面是客户端调用主要代码*/
memset(accountId_In,0x00,sizeof(accountId_In));
strcpy(accountId_In,argv[2]);
struct ns2__nsGetAccountBankCardListResponse r3;
soap_call_ns2__nsGetAccountBankCardList(&soap,server,"", accountId_In, &r3);
printf("size=%d\n",r3._x002dsize);/*此行可得到正确的值2*/
int i;
for(i=0;i<r3._x002dsize;i++)/*只能打印出第一个结构,第二个结构是乱的,哪里有错了?*/
{
printf("[%d]\n",(r3.cardList+i)->cardType);
printf("[%s]\n",(r3.cardList+i)->cardholderName);
printf("\n");
} |
|