- 論壇徽章:
- 0
|
接口要求實(shí)現(xiàn)輸入一個(gè)查詢條件,返回一組結(jié)構(gòu),類似于查詢明細(xì)。這樣想來是要返回結(jié)構(gòu)體數(shù)組的。
現(xiàn)在的問題是我在客戶端測(cè)試時(shí)只能得到數(shù)組個(gè)數(shù) 和 第一個(gè)結(jié)構(gòu)的內(nèi)容,是哪里出錯(cuò)了呢?是服務(wù)端的實(shí)現(xiàn)有問題 還是 客戶端取值有問題?
這個(gè)問題已經(jīng)困擾我?guī)滋炝,有哪位知道給指點(diǎn)下啊,代碼如下:
/**服務(wù)端接口定義如下**/
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);
/**我是這樣實(shí)現(xiàn)接口函數(shù)的,有問題嗎**/
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;
}
/*下面是客戶端調(diào)用主要代碼*/
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++)/*只能打印出第一個(gè)結(jié)構(gòu),第二個(gè)結(jié)構(gòu)是亂的,哪里有錯(cuò)了?*/
{
printf("[%d]\n",(r3.cardList+i)->cardType);
printf("[%s]\n",(r3.cardList+i)->cardholderName);
printf("\n");
} |
|