You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by mi...@nutechs.com on 2003/06/11 15:15:39 UTC
Beginner question
Hi,
I have experience with Java and XML, but am pretty new to SOAP and WSDL.
I've been able to invoke the demo web services provided at xmethods.com
using the Java client code provided with no problem. I've been trying to
invoke the Unisys Weather web service using the Currency Exchange Service
code as a starting point, with no success. After checking to see whether a
fault was generated, my code throws a java.lang.Exception. After doing
some research on WSDL, I believe part of the problem may be due to the
Unisys Weather web service not being encoded. I've included my code below.
If anyone would be willing to tell me where I've gone wrong, I'd really
appreciate it.
Thanks,
- Mike.
//
// sample client for the Unisys Weather service
//
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 UnisysWeatherClient {
public static String getWeather (URL url, String zipCode) throws Exception {
Call call = new Call ();
// Set encoding style. Use the standard SOAP encoding
String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
call.setEncodingStyleURI(encodingStyleURI);
// Set service locator parameters
call.setTargetObjectURI ("http://www.unisys.com/WebServices/GetWeatherText");
call.setMethodName ("GetWeatherText");
// Create the 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 result
if (resp.generatedFault ()) {
throw new Exception();
} else {
// Call was succesfull. Extract response parameter and return
Parameter result = resp.getReturnValue ();
String weather = (String) result.getValue();
return weather;
}
}
// Driver to illustrate invocation of service
public static void main(String[] args)
{
try {
URL url=new URL("http://weather.unisysfsp.com/PDCWebService/WeatherServices.asmx");
String zipCode = args[0];
String weather = getWeather(url,zipCode);
System.out.println(weather);
}
catch (Exception e) {e.printStackTrace();}
}
}
Re: Beginner question
Posted by Anne Thomas Manes <an...@manes.net>.
I suggest that you use Apache Axis (http://ws.apache.org/axis) rather than
Apache SOAP. Apache Axis provides much better support for document/literal.
Apache Axis is Apache's strategic Web services implementation. Apache SOAP
has been on life support for more than 2 years, and there's no plan to
upgrade it to support WSDL.
Anne
----- Original Message -----
From: <mi...@nutechs.com>
To: <so...@ws.apache.org>
Sent: Wednesday, June 11, 2003 9:15 AM
Subject: Beginner question
>
>
>
>
> Hi,
>
> I have experience with Java and XML, but am pretty new to SOAP and WSDL.
> I've been able to invoke the demo web services provided at xmethods.com
> using the Java client code provided with no problem. I've been trying to
> invoke the Unisys Weather web service using the Currency Exchange Service
> code as a starting point, with no success. After checking to see whether
a
> fault was generated, my code throws a java.lang.Exception. After doing
> some research on WSDL, I believe part of the problem may be due to the
> Unisys Weather web service not being encoded. I've included my code
below.
> If anyone would be willing to tell me where I've gone wrong, I'd really
> appreciate it.
>
> Thanks,
>
> - Mike.
>
>
> //
> // sample client for the Unisys Weather service
> //
>
> 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 UnisysWeatherClient {
>
> public static String getWeather (URL url, String zipCode) throws
Exception {
>
> Call call = new Call ();
>
> // Set encoding style. Use the standard SOAP encoding
> String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
> call.setEncodingStyleURI(encodingStyleURI);
>
> // Set service locator parameters
> call.setTargetObjectURI
("http://www.unisys.com/WebServices/GetWeatherText");
>
> call.setMethodName ("GetWeatherText");
>
> // Create the 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 result
> if (resp.generatedFault ()) {
> throw new Exception();
> } else {
>
> // Call was succesfull. Extract response parameter and return
> Parameter result = resp.getReturnValue ();
> String weather = (String) result.getValue();
> return weather;
> }
> }
>
> // Driver to illustrate invocation of service
> public static void main(String[] args)
> {
> try {
> URL url=new
URL("http://weather.unisysfsp.com/PDCWebService/WeatherServices.asmx");
> String zipCode = args[0];
>
> String weather = getWeather(url,zipCode);
> System.out.println(weather);
> }
> catch (Exception e) {e.printStackTrace();}
> }
> }
>