基于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>

 

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


基于Zend_Soap的webservice及其多语言通信(java)(二)
 将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));  

            

     }  

    

 } 

 

得到返回值为


基于Zend_Soap的webservice及其多语言通信(java)(二)
 这里请看客户端程序中的一段程序。

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

 

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

你可能感兴趣的:(java,webservice,ant,SOAP,Zend)