请高手帮忙看看,我哪里错了,关于JAVA用axis调用WebService的问题。
我是这么写的,可是返回的结果不对,是我参数传错了么?参数应该怎么写呢?
代码如下~
/**
     * @param args
     */
    public static void main(String[] args) throws ServiceException, RemoteException{
        try  
        {   
            // 服务端的url,需要根据情况更改。   
            String endpointURL = "http://116.236.252.205/rt/Service.asmx?WSDL";   
            Service service = new Service();   
            Call call = (Call) service.createCall();   
            call.setTargetEndpointAddress(new java.net.URL(endpointURL));   
            call.setSOAPActionURI("http://tempuri.org/" + "GetTrafficData");   
            call.setOperationName(new QName("Service", "GetTrafficData"));// 设置操作的名称。   
            // 由于需要认证,故需要设置调用的用户名和密码。   
            SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("http://tempuri.org/", "complexType");   
            soapHeaderElement.setNamespaceURI("http://tempuri.org/");   
            try  
            {   
                soapHeaderElement.addChildElement("strCustomID").setValue("user");   
                soapHeaderElement.addChildElement("strPassword").setValue("password");
                soapHeaderElement.addChildElement("strResult").setValue("实时状况");
            }   
            catch (SOAPException e)   
            {   
                e.printStackTrace();   
            }   
            call.addHeader(soapHeaderElement);   
            call.setReturnType(XMLType.XSD_STRING);// 返回的数据类型   
            call.addParameter("", XMLType.XSD_STRING, ParameterMode.IN);// 参数的类型   
            String ret = (String) call.invoke(new Object[] { "" });// 执行调用   
            System.out.println(ret);   
        }   
        catch (Exception e)   
        {   
            e.printStackTrace();   
        }   
    }其中
call.addParameter("", XMLType.XSD_STRING, ParameterMode.IN);// 参数的类型   
  String ret = (String) call.invoke(new Object[] { "" });// 执行调用  
这两个引号里应该写什么参数呢?下面的是SOAP1.2请求以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。POST /rt/Service.asmx HTTP/1.1
Host: 116.236.252.205
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetTrafficData xmlns="http://tempuri.org/">
      <strCustomID>string</strCustomID>
      <strPassword>string</strPassword>
      <strResult>string</strResult>
    </GetTrafficData>
  </soap12:Body>
</soap12:Envelope>我返回的结果是:<TrafficData CustomID=""><Result ErrorCode="-10001" Message="用户不存在" /></TrafficData>
请问是上面哪里写的错误了呢?
////////////////////////////////////////////////////////////////////////////////////////////
在线等
///////////////////////////////////////////////////////////////////////////////////////////
如果我要是改成这样的话
String ret = (String) call.invoke(new Object[] { "user","password","实时状况" });// 执行调用  
则报以下错误:AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: javax.xml.rpc.JAXRPCException: Number of parameters passed in (3) doesn't match the number of IN/INOUT parameters (1) from the addParameter() calls
 faultActor: 
 faultNode: 
 faultDetail: 
{http://xml.apache.org/axis/}stackTrace:javax.xml.rpc.JAXRPCException: Number of parameters passed in (3) doesn't match the number of IN/INOUT parameters (1) from the addParameter() calls
at org.apache.axis.client.Call.getParamList(Call.java:2059)
at org.apache.axis.client.Call.invoke(Call.java:2364)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at travl.action.aa.main(aa.java:46) {http://xml.apache.org/axis/}hostname:hp-laptop7javax.xml.rpc.JAXRPCException: Number of parameters passed in (3) doesn't match the number of IN/INOUT parameters (1) from the addParameter() calls
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.client.Call.invoke(Call.java:1828)
at travl.action.aa.main(aa.java:46)
Caused by: javax.xml.rpc.JAXRPCException: Number of parameters passed in (3) doesn't match the number of IN/INOUT parameters (1) from the addParameter() calls
at org.apache.axis.client.Call.getParamList(Call.java:2059)
at org.apache.axis.client.Call.invoke(Call.java:2364)
at org.apache.axis.client.Call.invoke(Call.java:1812)
... 1 more
请高手帮忙指点一下,谢谢

解决方案 »

  1.   

    Number of parameters passed in (3) doesn't match the number of IN/INOUT parameters (1) from the addParameter() calls
    看wsdl 你传入的参数类型是否错误
      

  2.   

    类型是一样的啊,都是STRING类型的!
    而且我把登陆的参数都写上了
    怎么能返回
    <TrafficData CustomID=""><Result ErrorCode="-10001" Message="用户不存在" /></TrafficData>
    这个呢?
    就是不存在也应该返回的是
    <TrafficData CustomID="user"><Result ErrorCode="-10001" Message="用户不存在" /></TrafficData>
    这样的啊
      

  3.   

    自己解决了,呵呵,谢谢各位关注:
    主要是这里写错了,导致参数没传递过去:
    最开始是这么写的:
    call.addParameter("", XMLType.XSD_STRING, ParameterMode.IN);// 参数的类型   之后改为:
    call.addParameter(new QName("http://tempuri.org/", "这里WebService里需要的接收的变量名"), XMLType.XSD_STRING, ParameterMode.IN);//参数的类型