IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  SOA and Web services  >

The Web services (r)evolution: Part 4

Web Services Description Language (WSDL)

developerWorks

Return to article


Listing 2: CurrencyExchangePortTypeProxy.java
        
import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.rpc.*;
import org.apache.soap.util.xml.*;
public class CurrencyExchangePortTypeProxy
{
 private Call call = new Call();
 private URL url = null;
 private String SOAPActionURI = "";
 private SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
 public CurrencyExchangePortTypeProxy() throws MalformedURLException
 {
 call.setTargetObjectURI("urn:xmethods-CurrencyExchange");
 call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");
 this.url = new URL("http://services.xmethods.net:80/soap");
 this.SOAPActionURI = "";
 }
 public synchronized void setEndPoint(URL url)
 {
 this.url = url;
 }
 public synchronized URL getEndPoint()
 {
 return url;
 }
 public synchronized float getRate(java.lang.String country1,
 java.lang.String country2) throws SOAPException
 {
 if (url == null)
 {
 throw new SOAPException(Constants.FAULT_CODE_CLIENT,
 "A URL must be specified via " +
 "CurrencyExchangePortTypeProxy.setEndPoint(URL).");
 }
 call.setMethodName("getRate");
 Vector params = new Vector();
 Parameter country1Param = new Parameter("country1", java.lang.String.class, country1, null);
 params.addElement(country1Param);
 Parameter country2Param = new Parameter("country2", java.lang.String.class, country2, null);
 params.addElement(country2Param);
 call.setParams(params);
 Response resp = call.invoke(url, SOAPActionURI);
 // Check the response.
 if (resp.generatedFault())
 {
 Fault fault = resp.getFault();
 throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
 }
 else
 {
 Parameter retValue = resp.getReturnValue();
 return ((Float)retValue.getValue()).floatValue();
 }
 }
}
      

Return to article

    关于 IBM 隐私条约 联系 IBM 使用条款