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

📄 tempclient.java

📁 JAVA分布式程序学习的课件(全英文)
💻 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 void main(String[] args) {      try	{	     URL url= new URL(                 "http://services.xmethods.com:80/soap/servlet/rpcrouter");	     String zipcode= "93420";	     float temp = getTemp(url, zipcode);	     System.out.println("The temperature is " + temp); 	 }    catch (Exception e) {       e.printStackTrace();    }   } //end main   public static float getTemp (URL url, String zipcode)        throws Exception {	   Call call = new Call ();      // SOAP encoding specification	   String encodingStyleURI = Constants.NS_URI_SOAP_ENC;	   call.setEncodingStyleURI(encodingStyleURI);      // Set service locator parameters	   call.setTargetObjectURI ("urn:xmethods-Temperature");   	call.setMethodName ("getTemp");      // Create parameter vector	   Parameter aParam =       new Parameter("zipcode", String.class, zipcode, null);	   Vector params = new Vector ();	   params.addElement (aParam);	   call.setParams (params);      // Invoke the service       Response resp = call.invoke (url,"");      // Process the response    	if (resp.generatedFault ()) {         // The call was unsuccessful	      Fault f = resp.getFault(); // an error occurred          System.err.println( "Fault= " + f.getFaultCode() +            ", " + f.getFaultString() );         throw new Exception( );	   }       else {         // The call was successful.          // Extract return value and return the result	      Parameter result = resp.getReturnValue ();	      Float readOut=(Float) result.getValue();	      return readOut.floatValue();	   }    } //end getTemp} //end class

⌨️ 快捷键说明

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