找一些webservice的文章来看看http://dns.tlw.cn/22227.htm否则就算别人帮你做了,以后你还是不会

解决方案 »

  1.   


    import java.net.*;
    import java.util.*;import org.apache.soap.*;
    import org.apache.soap.rpc.*;public class TempClient {    public static String getName(URL url) throws Exception {
            Call call = new Call();        // Service uses standard SOAP encoding
            String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
            call.setEncodingStyleURI(encodingStyleURI);        // Set service locator parameters
            call.setTargetObjectURI("urn:xmethods-Temperature");
            call.setMethodName("getName");        // Create input parameter vector
    //        Vector params = new Vector();
    //        params.addElement(new Parameter("zipcode", String.class, "ss", null));
    //        call.setParams(params);        // Invoke the service ....
            Response resp = call.invoke(url, "");        // ... and evaluate the response
            if (resp.generatedFault()) {
                System.out.println("" + resp.getFault().getFaultString());
    //            resp.getFault().get
                throw new Exception();
            } else {
    // Call was successful. Extract response parameter and return result
                Parameter result = resp.getReturnValue();
                return             result.getValue() + "";
    //            Float rate = (Float) result.getValue();
    //            return rate.floatValue();
            }    }
        public static float getTemp(URL url, String zipcode) throws Exception {        Call call = new Call();        // Service uses standard SOAP encoding
            String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
            call.setEncodingStyleURI(encodingStyleURI);        // Set service locator parameters
            call.setTargetObjectURI("urn:xmethods-Temperature");
            call.setMethodName("getTemp");        // Create input parameter vector
            Vector params = new Vector();
            params.addElement(new Parameter("zipcode", String.class, zipcode, null));
            call.setParams(params);        // Invoke the service ....
            Response resp = call.invoke(url, "");        // ... and evaluate the response
            if (resp.generatedFault()) {
                throw new Exception();
            } else {
    // Call was successful. Extract response parameter and return result
                Parameter result = resp.getReturnValue();
                Float rate = (Float) result.getValue();
                return rate.floatValue();
            }
        }// Driver to illustrate service invocation
        public static void main(String[] args) {
            try {            URL url = new URL("http://services.xmethods.net:80/soap/servlet/rpcrouter");
    //     String zipcode= "94041";
                String zipcode = "94041";
                long time = System.currentTimeMillis();
                float temp = getTemp(url, zipcode);
                System.out.println("" + (System.currentTimeMillis() - time));
                System.out.println(temp);            time = System.currentTimeMillis();
                url = new URL("http://localhost:80/axis/Test.jws");
                String name = getName(url);
                System.out.println("" + (System.currentTimeMillis() - time));
                System.out.println("name:" + name);        } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
      

  2.   

    我这个也是学ws的时候用的例子,和你的不是同一个ws,可以参考