Skip to main content

Part 4

Web Services Description Language (WSDL)

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