日期:2014-05-19  浏览次数:20772 次

java调用php webservice接口问题
利用axis调用代码:
Java code

import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.description.OperationDesc;
import org.apache.axis.description.ParameterDesc;

public class TestInteface2 {
    public static void main(String[] args) throws Exception {
        String url = "省略";
        
        String method = "method";
        String result = getOrderInfo(url,"domain",method, null);
        System.out.println(result);
    }
    
    public static String getOrderInfo(String url, String domain, String method, String req) throws Exception {
        OperationDesc oper = new OperationDesc();
        ParameterDesc param = new ParameterDesc(
            new QName(domain, "xmlDoc"),
            ParameterDesc.IN, 
            new QName("http://www.w3.org/2001/XMLSchema", "string"), 
            String.class, 
            false,
            false
        );
        ParameterDesc param2 = new ParameterDesc(
            new QName(domain, "xmlDoc"),
            ParameterDesc.IN, 
            new QName("http://www.w3.org/2001/XMLSchema", "string"), 
            String.class, 
            false,
            false
        );
        ParameterDesc param3 = new ParameterDesc(
            new QName(domain, "xmlDoc"),
            ParameterDesc.IN, 
            new QName("http://www.w3.org/2001/XMLSchema", "string"), 
            String.class, 
            false,
            false
        );
        
        param.setOmittable(true);
        oper.addParameter(param);
        oper.addParameter(param2);
        oper.addParameter(param3);
        oper.setReturnType(
            new QName("http://www.w3.org/2001/XMLSchema", "string")
        );
        
        Service service = new Service();
        Call call = (Call) service.createCall();
        call.setTargetEndpointAddress(url);
        call.setOperation(oper);
        call.setSOAPActionURI(domain+method);
        call.setOperationName(new QName(domain, method));
        
        try {        
            Object resp = call.invoke(new Object[] {"1","2","3"});

            if (resp instanceof java.rmi.RemoteException) {
                throw (java.rmi.RemoteException)resp;
            }
            else {
                try {
                    return (String) resp;
                } catch (Exception _exception) {
                    return (String) org.apache.axis.utils.JavaUtils.convert(resp, String.class);
                }
            }
        } catch (org.apache.axis.AxisFault axisFaultException) {
            throw axisFaultException;
        }
    }
}


运行结果:
有正常返回值。但总不是期望得到的,就比如我要按学号查某学生的的信息,总是返回学号不存在,但可以确定学号是存在的。但用.net去调用却一切正常。搞不明白问题出哪。

------解决方案--------------------
call.setSOAPActionURI(domain+method);
改成
 call.setSOAPActionURI(domain+"/"+method);