基于Zend_Soap的webservice及其多语言通信(java)(二)

前者用Zend_Soap完成webservice以后,需要与java进行通信,这里我们只要用一个WSDL文件就可以搞定,当然,这个文件我们已经有了,IE上已经直接显示了,可以把它保存为wsdl文件,其中具体定义的内容比较复杂,我们这里只谈应用。

   java端的环境.

     1)安装jdk。

     2) 用axis1进行与php之间的通信,所以要下载axis1.4。

     3)这里用到了ant与axis1对wsdl进行解译成客户端,所以要安装ant.

     以下是ant任务的定义,主要是为了生成客户端程序。

<?xml version="1.0" encoding="UTF-8"?>
<project name="wsclient" default="all" basedir=".">
<property name="axis.home" value="C:\axis-1_4" />
<property name="options.output" location="../src"/>
<path id="axis.classpath"> 
<fileset dir="${axis.home}/lib"> 
<include name="**/*.jar" />
</fileset>    
</path> 
<taskdef resource="axis-tasks.properties" classpathref="axis.classpath" /> 
<target name="init">      
<echo>Warning: please update the associated WSDL file(s) in the folder wsdl before running the target!</echo>  
<echo>Warning: Just run the target(s) related with your developing work!</echo>  
<echo>  
</echo> 
</target> 
<target name="-WSDL2Axis" depends="init"> 
<mkdir dir="${options.output}"/>     
<axis-wsdl2java  serverside="false" output="${options.output}" url="${options.WSDL-URI}" verbose="true"/> 
</target> 
<target name="all">   
<antcall target="GatewayService"/> 
</target>  
<target name="GatewayService">
<antcall target="-WSDL2Axis">   
<param name="options.WSDL-URI" location="gateway.wsdl"/>    
</antcall> 
</target>  
</project>

 

 生成后的程序结构如下图所示



 将axis1的类库放入到classpath中来,于是调用客户端程序与php通信

package client;  

    

    

 import java.net.MalformedURLException;  

 import java.net.URL;  

 import java.rmi.RemoteException;  

    

 import javax.xml.namespace.QName;  

 import javax.xml.rpc.ServiceException;  

    

 import localhost.ZFDEMO.admin.soap.index.Custom_Soap_GatewayServiceLocator;  

 import localhost.ZFDEMO.admin.soap.index.MsgResp;  

 import localhost.ZFDEMO.admin.soap.index.User;  

 import localhost.ZFDEMO.admin.soap.index.UserPriority;  

 import localhost.ZFDEMO.admin.soap.index.Userole;  

    

 import org.apache.axis.client.Call;  

 import org.apache.axis.client.Service;  

    

    

 public class SoapClient {  

    

     /**  

      * @param args  

      * @throws ServiceException   

      * @throws RemoteException   

      */ 

     public static void main(String[] args) throws RemoteException, ServiceException {  

            

         Custom_Soap_GatewayServiceLocator locator =new Custom_Soap_GatewayServiceLocator();  

         locator.setEndpointAddress("Custom_Soap_GatewayPort", "http://localhost/ZFDEMO/admin/soap/index");  

         MsgResp logonRsp =locator.getCustom_Soap_GatewayPort().logonUser("刘少奇", "1111", "cc");  

         MsgResp logoutRsp =locator.getCustom_Soap_GatewayPort().logoutUser("刘少奇", "1111");  

         Userole userole =locator.getCustom_Soap_GatewayPort().getUserRole("刘少奇", "12345");  

         UserPriority up =locator.getCustom_Soap_GatewayPort().getUserPriority("刘少奇", "12345");  

         MsgResp rms =locator.getCustom_Soap_GatewayPort().modifyUser(new String[]{"1","刘少奇","男"}, "1111");  

            

         System.out.println(TypeUtil.typeToString("msresp for logonUser is ", logonRsp));  

         System.out.println(TypeUtil.typeToString("msresp for logoutUser is ", logoutRsp));  

         System.out.println(TypeUtil.typeToString("resp for userole is ", userole));  

         System.out.println(TypeUtil.typeToString("resp for UserPriority is ", up));  

         System.out.println(TypeUtil.typeToString("msresp for modifyUser is ", rms));  

            

     }  

    

 } 

 

得到返回值为



 这里请看客户端程序中的一段程序。

MsgResp rms =locator.getCustom_Soap_GatewayPort().modifyUser(new String[]{"1","刘少奇","男"}, "1111");

 

这里的一个string的数组,原则上应为Object的数组,因为是传入参数,所以比较好理解,这是因为php端定义了一个array类型的数据结构,如果这里的MsgResp是一个这样的数组你觉得这个数据结构好用吗?所以这里就是前篇文章中所说到的array在多语言通信中的不好的地方。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值