Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

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