/*
 * Created on 25 nov. 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package localhost.Axis1_2.HelloWorld_jws;

import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;

/**
 * @author Xavier
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TestCall {
	private static String qnameService = "HelloWorldService";

	private static String qnamePort = "HelloWorld";

	private static String BODY_NAMESPACE_VALUE = "http://localhost:8080/Axis1_2/HelloWorld.jws";

	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/encoding/";
	
	private static String add = "http://localhost:1234/Axis1_2/HelloWorld.jws";


	public static void main(String[] args) {
        System.out.println("Endpoint address = " + add);

        try {
            ServiceFactory factory = 
                ServiceFactory.newInstance();
            Service service = 
                factory.createService(
                new QName(qnameService));
    
            QName port = new QName(qnamePort);
    
            Call call = service.createCall(port);
            call.setTargetEndpointAddress(add);
    
            //call.setProperty("javax.xml.rpc.soap.http.soapaction.use" , new Boolean(true));
            //call.setProperty("javax.xml.rpc.soap.http.soapaction.uri", "http://supplychainserver.com/webservices/RechercherCommune");
            call.setProperty(ENCODING_STYLE_PROPERTY,
                URI_ENCODING);
            call.setProperty("javax.xml.rpc.soap.operation.style", "rpc");
            QName QNAME_TYPE_STRING = 
                        new QName(NS_XSD, "string");
            call.setReturnType(QNAME_TYPE_STRING);

            call.setOperationName(
                new QName(BODY_NAMESPACE_VALUE,"sayWhat"));
            //call.addParameter("commune", QNAME_TYPE_STRING, 
            //    ParameterMode.IN);
            //call.addParameter("departement", QNAME_TYPE_STRING, 
            //        ParameterMode.IN);
            //String[] params = {"argenteuil", "val d'oise"};
            String[] params = {};

            Object result = call.invoke(params);
            System.out.println(result);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
	}
}
