users@jax-rpc.java.net

Re: Dynamic Client

From: Sudhir <sudhir_at_INFOLEAD.COM>
Date: Wed, 24 Apr 2002 18:58:25 -0700

Arun,
 Thanks for the reply. I was trying to access one of the (supposedly)
publicly hosted web service published in xmethods.com.
I have a new problem. Now I am trying to access another web service, which
takes int as parameter and returns a String. The snippet I am using for that
is

call.addParameter("aNumber", QNAME_TYPE_INTEGER,
ParameterMode.PARAM_MODE_IN);
Integer[] params = { new Integer(100) };
String result = (String)call.invoke(params);

But I am getting the exception as

deserialization error: deserialization error: deserialization error:
 unexpected element type: expected={http://www.w3.org/2001/XMLSchema}int,
actual={http://www.w3.org/2001/XMLSchema}string
        at
com.sun.xml.rpc.encoding.ObjectSerializerBase.deserialize(ObjectSerializerBa
se.java:194)
        at
com.sun.xml.rpc.client.dii.CallInvokerImpl._readFirstBodyElement(CallInvoker
Impl.java:154)
        at
com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:154)
        at
com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:49)
        at com.sun.xml.rpc.client.dii.CallImpl.invoke(CallImpl.java:227)
        at CountryClient.main(CountryClient.java:47)
CAUSE:
deserialization error: deserialization error: unexpected element type:
expected={http://www.w3.org/2001/XMLSchema}int,
actual={http://www.w3.org/2001/XMLSchema}string
        at
com.sun.xml.rpc.encoding.ReferenceableSerializerImpl.deserialize(Referenceab
leSerializerImpl.java:148)
        at
com.sun.xml.rpc.encoding.soap.SOAPResponseSerializer.doDeserialize(SOAPRespo
nseSerializer.java:104)
        at
com.sun.xml.rpc.encoding.ObjectSerializerBase.deserialize(ObjectSerializerBa
se.java:160)
        at
com.sun.xml.rpc.client.dii.CallInvokerImpl._readFirstBodyElement(CallInvoker
Impl.java:154)
        at
com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:154)
        at
com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:49)
        at com.sun.xml.rpc.client.dii.CallImpl.invoke(CallImpl.java:227)
        at CountryClient.main(CountryClient.java:47)

The message element of the WSDL looks like
 <message name="NumToWords_EnglishRequest">
  <part name="aNumber" type="xs:int" />
  </message>
- <message name="NumToWords_EnglishResponse">
  <part name="return" type="xs:string" />
  </message>

What am I doing wrong now? The exception says that I am sending a String.
But I am sending an Integer. Since this is RPC, I presume we cant send the
primitive 'int' as such. Or is there a way to do that or using wrapper
Integer class is the correct way?

Thanks
Sudhir
----- Original Message -----
From: "Arun Gupta" <arun.gupta_at_SUN.COM>
To: <JAXRPC-INTEREST_at_JAVA.SUN.COM>
Sent: Wednesday, April 24, 2002 1:19 PM
Subject: Re: Dynamic Client


> Hi Sudhir,
>
> Please see inline comments.
>
> Sudhir wrote:
>
> > Hi All,
> >
> > I am trying to generate an JAX-RPC client dynamically. I dont have
> > access to the WSDL till the runtime. I used the following code:
> >
> >
> >
> > ServiceFactory factory = ServiceFactory.newInstance();
> > Service service = factory.createService(new
> > QName(qnameService));
> >
> >
> >
> > QName port = new QName(qnamePort);
> >
> >
> >
> > Call call = service.createCall();
> > call.setPortTypeName(port);
> > call.setTargetEndpointAddress(endpoint);
> >
> >
> >
> > call.setProperty(Call.SOAPACTION_USE_PROPERTY, new
> > Boolean(true));
> > call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
> > call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
> > QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
> > call.setReturnType(QNAME_TYPE_STRING);
> >
> >
> >
> >
> > call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
> > "getPopulation"));
> > call.addParameter("countryName", QNAME_TYPE_STRING,
> > ParameterMode.PARAM_MODE_IN);
> > String[] params = { new String("India") };
> >
> >
> >
> > String result = (String)call.invoke(params);
> > System.out.println(result);
> >
> >
> >
> > qnameService is the name attribute of the service element from the wsdl.
> >
> > port is the name attribute of the portType element from the wsdl.
> >
> > the wsdl specifies no soapaction value
> >
> > getPopulation is the service supported by the wsdl which takes one
> > String parameter and returns a String.
> >
> >
> >
> > When I try to run this program, I get the following exception:
> >
> >
> >
> > java CountryClient http://maxwell.c
s.uga.edu:8888/soap/servlet/rpcrouter
> > HTTP transport error: java.net.ConnectException: Connection refused:
> > connect
> > at
> >
com.sun.xml.rpc.client.http.HttpClientTransport.invoke(HttpClientTransport.j
ava:176)
> > at
> > com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:64)
> > at
> >
com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:49)
> > at com.sun.xml.rpc.client.dii.CallImpl.invoke(CallImpl.java:227)
> > at CountryClient.main(CountryClient.java:47)
> >
>
> Considering that your "endpoint" variable is set to args[0], this
> exception tells me that your endpoint is not accessible. Please ensure
> that your endpoint is accessible, by starting your http server, and then
> try invoking the service.
>
> Thanks for your interest in JAX-RPC.
>
> Regards,
> -Arun
>
> >
> >
> > CAUSE:
> >
> > java.net.ConnectException: Connection refused: connect
> > at java.net.PlainSocketImpl.socketConnect(Native Method)
> > at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:320)
> > at
> > java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:133)
> > at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:120)
> > at java.net.Socket.<init>(Socket.java:273)
> > at java.net.Socket.<init>(Socket.java:100)
> > at sun.net.NetworkClient.doConnect(NetworkClient.java:50)
> > at sun.net.www.http.HttpClient.openServer(HttpClient.java:331)
> > at sun.net.www.http.HttpClient.openServer(HttpClient.java:517)
> > at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
> > at sun.net.www.http.HttpClient.<init>(HttpClient.java:277)
> > at sun.net.www.http.HttpClient.New(HttpClient.java:289)
> > at
> >
com.sun.xml.rpc.client.http.handler.HttpURLConnection.connect(HttpURLConnect
ion.java:441)
> > at
> >
com.sun.xml.rpc.client.http.handler.HttpURLConnection.getOutputStream(HttpUR
LConnection.java:488)
> > at
> >
com.sun.xml.rpc.client.http.HttpClientTransport.invoke(HttpClientTransport.j
ava:84)
> > at
> > com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:64)
> > at
> >
com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:49)
> > at com.sun.xml.rpc.client.dii.CallImpl.invoke(CallImpl.java:227)
> > at CountryClient.main(CountryClient.java:47)
> >
> >
> >
> > Am I missing something? Am I doing something wrong?
> >
> >
> >
> > http://www.cs.uga.edu/~sent/xmethods/CountryInfoLookup.wsdl
> > <http://www.cs.uga.edu/%7Esent/xmethods/CountryInfoLookup.wsdl> is
> > the location of the WSDL file.
> >
> >
> >
> > Thanks
> >
> > Sudhir
> >
> >
> >
> >
> >
> >
> >
>
> --
> =============================================
> There is only one me, I must live myself!
> There is only one today, I must live itself!
> =============================================
> http://members.tripod.com/~apgupta/index.html
> =============================================
>