users@jax-rpc.java.net

Dynamic Client

From: Sudhir <sudhir_at_INFOLEAD.COM>
Date: Wed, 24 Apr 2002 11:03:48 -0700

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.cs.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.java: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)

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(HttpURLConnection.java:441)
        at com.sun.xml.rpc.client.http.handler.HttpURLConnection.getOutputStream(HttpURLConnection.java:488)
        at com.sun.xml.rpc.client.http.HttpClientTransport.invoke(HttpClientTransport.java: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 is the location of the WSDL file.

Thanks
Sudhir