users@glassfish.java.net

Calling a Web Service making use of DII

From: <glassfish_at_javadesktop.org>
Date: Mon, 26 Feb 2007 00:40:50 PST

Hello,

I would like to know if there is a way to call a Web Service making use of Dynamic Invocation Interface and JEE 5 api, only using wsdl file without generating proxy classes with wsimport. The code should be similar to the following examples (it doesn't work because I have the following exception:

operation style: "rpc" not supported
        at com.sun.xml.rpc.client.dii.BasicCall.unsupportedOperationStyleException(BasicCall.java:566)
        at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:498)
)

public class Main {
    
    private static String qnameService = "TestService";
    private static String qnamePort = "TestPort";
    
    private static String BODY_NAMESPACE_VALUE = "http://org.irriis.mit";
    private static String ENCODING_STYLE_PROPERTY = "javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD = "http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING = "http://schemas.xmlsoap.org/soap/http";
    
    
    
    /** Creates a new instance of Main */
    public Main() {
        try {
            ServiceFactory factory = ServiceFactory.newInstance();
            Service service = factory.createService(new QName(qnameService));
            QName port = new QName(qnamePort);
            Call call = service.createCall(port);
            call.setTargetEndpointAddress("http://erg4082:8080/JBossWsServer/TestSession?wsdl");
            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, "saluto"));
            call.addParameter("String_1", QNAME_TYPE_STRING, ParameterMode.IN);
            String[] params = { "Murph!" };
            String result = (String)call.invoke(params);
            System.out.println(result);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
    }
[Message sent by forum member 'giordano48' (giordano48)]

http://forums.java.net/jive/thread.jspa?messageID=205208