⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tempclient.java

📁 《JAVA WEB服务应用开发详解》代码
💻 JAVA
字号:
    //TempClient.java
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import org.apache.soap.util.xml.*;
    import org.apache.soap.*;
    import org.apache.soap.rpc.*;
    
    public class TempClient{
    
        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.com:80/soap/servlet/rpcrouter");
    	    String zipcode= "94041";
    	    float temp = getTemp(url,zipcode);
    	    System.out.println(temp);
    	}
        catch (Exception e) {e.printStackTrace();}
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -