java调用php的webservice接口

1。通过URL访问接口:

http://192.168.10.227/ebsService/services/ebsService?wsdl

2.找到方法名,地址

<operation name="sendAnnouncement">

<soap:address location="http://10.30.67.55:8085/service/Service.php"/>

3.下载2个jar

axis.jar,commons-discovery.jar

4.编写调用代码

package test;

import javax.xml.namespace.QName;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.jeecgframework.core.util.StringUtil;

public class JvsTest {

	public static void main(String[] args) {

	        //String endpoint = "http://testweb.dev.php/testWebService/testWebService.php";//该段就是上面刚将的地址   
	       Service service = new Service();  
	       Call call;  
	       
	       //xml
	        String ggXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><request><title></title></request>";
	       
	        //指定类型
	        String namespace = "http://webserver.server.com/";
	        try {  
	        call = (Call) service.createCall();  
	        call.setTargetEndpointAddress(new java.net.URL(endpoint));  
	        //接口名称
	        call.setOperationName(new QName(namespace, "sendAnnouncement"));
	        
//          // 此处需要配置传入参数类型与参数名称,如果未设置jax-ws则无法接受参数,会认为传入的参数为null <br>             
            //这里的参数名字必须为arg0,否则接受不到参数
	        call.addParameter("arg0",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
	        //多个参数
	        // call.addParameter("arg1",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
	        // call.addParameter("arg2",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
	        
	        
	        //参数
	        String param = new String(ggXML.getBytes(),"utf-8");//如果没有加这段,中文参数将会乱码  
	        
	        //放入参数
	        String s = (String) call.invoke(new Object[] {param});  
	        //String s = (String) call.invoke(new Object[] {param,arg1,arg2});  
	        s = new String(s.getBytes("ISO-8859-1"));//如果没有转换编码,中文也会乱码 
	        
	        //输出返回结果
	        System.out.println(s);  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值