有一webservice可查询股票实时信息,http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?WSDL, 可是我没有写过webservice,写了个demo发现得不到数据,总是返回null,请高手指点, 只写一个main方法就行,请确保能运行且得到正确的返回结果.请注明需要下载哪些jar包.public class Test {
public static void main(String[] args) {
try {
String endpoint = "http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?WSDL";
Service service = new Service();

Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);

call.setOperationName("getStockInfoByCode");
call.addParameter("theStockCode",XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);// 接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
String code = "sh000001";
String[] result = (String[]) call.invoke(new Object[]{code});
// 给方法传递参数,并且调用方法
System.out.println("result is " + result);
}
catch (Exception e) {
System.err.println(e.toString()); }
}}分数将集中给正确的解答者.

解决方案 »

  1.   

    用apache 的 axis,你search一下代码很多。我很久很开发ws了,手头没code!
      

  2.   

    我上面的代码就是用axis, 只是不ok.
      

  3.   

    public Call WEBSERVICE_init(String CallOperationName)
        {
            Service service = new Service();
            Call call = null;
            try
            {
                call = (Call) service.createCall();
                call.setTimeout(new Integer(1000*60*60));       
                call.setTargetEndpointAddress("http://10.110.113.92:8085/kfagent/services/AgentQueryUserNum");           
                
                
                call.setOperationName(CallOperationName);
                call.setReturnType(XMLType.XSD_STRING);
                
            }
            catch (ServiceException e)
            {
                e.printStackTrace();
            }
            return call;
        }

     // 调用接口方法
        public String getXmlUserQueryStates()
        {
            String result = "";
            Call m_Call = WEBSERVICE_init("getXmlUserQueryStates");
            m_Call.addParameter("pageInd", XMLType.XSD_STRING, ParameterMode.IN);
            m_Call.addParameter("queryType", XMLType.XSD_STRING, ParameterMode.IN);
            m_Call.addParameter("queryContext", XMLType.XSD_STRING,
                    ParameterMode.IN);
            m_Call.addParameter("areaId", XMLType.XSD_STRING, ParameterMode.IN);        Object[] parAry = new Object[] { "1", "1", "+8615810511400", "-1" };
            try
            {
                result = (String) m_Call.invoke(parAry);
            }
            catch (RemoteException e)
            {
                e.printStackTrace();
                System.out.println("getXmlUserQueryStates获取参数失败!");
            }
            return result;
        }
        public static void main(String[] args)
        {
            TestService ts = new TestService();
            
            //查询用户状态
            //String strPending = (String) ts.getXmlUserQueryStates();       
                        
            System.out.println(strPending.trim());
            System.out.println("WebService 调用结束!");
        }
      

  4.   

    你的endpoint应该是这个:http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx
    而不是:http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmxhttp://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx?WSDL是用来测试web service是否已经成功启动和运行的
      

  5.   

    根据这个wsdl生成客户端,直接调用其接口即可