axis2c 做的客户端程序接收基于Axis2 java的Webservice服务返回的超长字符串

来源:互联网 发布:淘宝网电表箱装饰画 编辑:程序博客网 时间:2024/04/29 09:44

问题描述: 

  axis2c写的客户端程序与java开发的Webservice服务器端程序进行交互时,若WebService服务端的接口返回一个超长字符串,在服务器端使用String作为返回类型。当客户端请求该服务时,该服务会在服务端运行且运行得到结果是正确的,但在客户端接收的该字符串为null. 为什么请求可以被执行且结果是正确的,但该字符串无法正确的返回到客户端。

 

解决方法:

   在服务器端Webservice不使用String作为返回类型,而选择byte[]。客户端利用axis2c工具生成Stub
eg:
java WSDL2C -uri interoptestdoclitparameters.wsdl -d adb -u
或不使用adb数据绑定方式
java WSDL2C -uri interoptestdoclitparameters.wsdl -d none

 

在编写客户端代码时,调用类似以下函数adb_getDepStringResponse_get_return ,返回一个axutil_base64_binary_t* 类型的指针数据 ,而不是对应于服务器端得返回类型为String的char *。在处理axutil_base64_binary_t* 类型的指针数据时,可以参照下面的方法得到我们想要的char * 类型的数据。
 
 adb_getDepStringResponse_t * depStringRes = NULL ;
 axis2_char_t* str = NULL ;
 char * base64Str = NULL ;
 axutil_base64_binary_t * baseStrRes = NULL ;
 int len ;

 baseStrRes = adb_getDepStringResponse_get_return( depStringRes, env);
 printf("The getDeptString len  : %d/n" ,axutil_base64_binary_get_decoded_binary_len( baseStrRes, env));

 base64Str = axutil_base64_binary_get_encoded_binary( baseStrRes, env) ;
 //printf("The getDeptString  : %s/n" ,axutil_base64_binary_get_encoded_binary( baseStrRes, env));

 //返回字符串的长度
 *len = axutil_base64_decode_len(base64Str) ;
 printf("the len is %d /n" ,*len) ;
 //返回的字符串
 *str = (char *)malloc(sizeof(char)*(*len+1)) ; //内存分配为len+1
 axutil_base64_decode( *str, base64Str);
 printf("The ExportTree  : %s/n" ,*str);

原创粉丝点击