Hi Rey,
Unfortunately, I get this error when I try to cast the web service response to a String:
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:189)
at org.apache.axis.encoding.DeserializationContextImpl.startElement(DeserializationContextImpl.java:949)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java(Compiled Code))
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:718)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:232)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:346)
at org.apache.axis.client.Call.invoke(Call.java:2234)
at org.apache.axis.client.Call.invoke(Call.java:2133)
at org.apache.axis.client.Call.invoke(Call.java:1656)
at UnisysWeatherClient2.main(UnisysWeatherClient2.java:39)
[ERROR] Call - -Exception: <org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.>
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
this is the code I am using:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class UnisysWeatherClient2
{
public static void main(String [] args) {
try {
String endpoint = "http://weather.unisysfsp.com/PDCWebService/WeatherServices.asmx?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setOperationStyle("wrapped"); // added
call.setOperationUse("literal"); // added
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName ( "http://www.unisys.com/WebServices/", "GetWeather" ) );
call.setProperty ( Call.SOAPACTION_URI_PROPERTY, "http://www.unisys.com/WebServices/GetWeather" );
call.addParameter(new javax.xml.namespace.QName (
"http://www.unisys.com/WebServices/", "ZipCode"),
org.apache.axis.Constants.XSD_STRING,
javax.xml.rpc.ParameterMode.IN
);
call.setReturnType ( org.apache.axis.Constants.XSD_STRING );
String ret = (String) call.invoke ( new Object[] { args[0] } );
System.out.println("Sent: '" + args[0] + "', got: '" + ret + "'");
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
Thanks,
Michael Sobczak
NuTechs, Inc.
6785 Telegraph Road, Suite 350
Bloomfield Hills, MI 48301
pager: (248) 316-6524
" Reynardine" <[EMAIL PROTECTED]>
06/18/2003 03:15 PM
|
To: [EMAIL PROTECTED] cc: Subject: Re: Handling complex response type |
Michael,
you might try something like...
java.lang.String xmlString = getWeather();
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(dtdValidate || xsdValidate);
SAXParser saxParser = spf.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
final SAXParseFTSE tHandler = new SAXParseFTSE (Debug);
xmlReader.setContentHandler(tHandler);
xmlReader.setErrorHandler(tHandler);
ByteArrayInputStream bais =
new ByteArrayInputStream (xmlString.getBytes());
xmlReader.parse( new InputSource(bais) );
bais.close();
You may have to pre-process your XML string for ampersands and quotes before throwing it at the parser.
Rey.
----- Original Message -----
From: [EMAIL PROTECTED]
Date: Wed, 18 Jun 2003 13:51:57 -0400
To: [EMAIL PROTECTED]
Subject: Handling complex response type
>
>
>
>
> Hi,
>
> Through the help of the axis-user mailing list, I've been able to create a
> Java client that invokes the Unisys Weather web service and returns the
> weather. (I've included a link below.) The method I'm calling,
> GetWeatherText, returns all of the weather details, including at ten-day
> forecast, as one long string:
>
> <?xml version="1.0" encoding="utf-8" ?>
> <string xmlns="http://www.unisys.com/WebServices/">Weather for Livonia, MI
> (48150) at 5 PM EDT 17 JUN 03. Sunrise at 5:56 AM. Sunset at 9:12 PM.
> Forecast for TONIGHT is MOSTLY CLOUDY DURING THE EARLY EVENING...THEN
> BECOMING PARTLY CLOUDY. SCATTERED SHOWERS WITH AN ISOLATED
> THUNDERSTORM...ENDING AROUND 10 PM...FOLLOWED BY AREAS OF FOG DEVELOPING
> AFTER 3 AM. LOWS 57 TO 61. LIGHT AND VARIABLE WINDS. CHANCE OF RAIN 30
> PERCENT....</string>
>
> The Unisys Weather web service has an alternate method, GetWeather, that
> returns all of the above data as a complex type object. I've gone ahead
> and used WSDL2Java to generate a client stub that I've used to call
> GetWeather and then invoke the methods of the response object to in a new
> Java application that returns select pieces of the above data to the user.
> This all works fine, but I'm a bit concerned about hard-coding what I want
> to extract from the returned object. If my users want a piece of weather
> data added to or removed from the response they receive, I would need to
> update and recompile the Java client code.
>
> I would prefer being able to process the result using a stylesheet, which
> can be updated without recompiling any code. Is there a way that I can
> have the xml of the response returned in a Stream, StringBuffer or String
> that I could then use Xalan to style in whatever way I choose?
>
>
> Thanks,
>
> Michael Sobczak
> NuTechs, Inc.
> 6785 Telegraph Road, Suite 350
> Bloomfield Hills, MI 48301
> pager: (248) 316-6524
>
> PS: Unisys Weather web service:
> http://weather.unisysfsp.com/PDCWebService/WeatherServices.asmx?wsdl
>
--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers