/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.wsdl.WSDLException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.soap.Constants;

import java.util.Map;
import javax.wsdl.Definition;
import javax.wsdl.Types;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
/**
 *
 * @author ULAN
 */
public class externalWS extends util {
    
  public static void getWS(String args)
  {

      String s=args;
      String [] ars;
      ars=s.split("#");
   try {

            WSDLFactory factory = WSDLFactory.newInstance();
            // create an object to read the WSDL file
            WSDLReader reader = factory.newWSDLReader();
            // pass the URL to the reader for parsing and get back a WSDL definiton
            /*Definition wsdlInstance = reader.readWSDL(null, "http://localhost:8080/axis2/services/HelloAxisWorld?wsdl");
            // get a map of the five specific parts a WSDL file
            Types types = wsdlInstance.getTypes();
            Map messages = wsdlInstance.getMessages();
            Map portTypes = wsdlInstance.getPortTypes();
            Map bindings = wsdlInstance.getBindings();
            Map services = wsdlInstance.getServices();
            String targetNameSpace,parameters,tmp,r="ana";
            String methodd=ars[1];

         
            targetNameSpace = wsdlInstance.getTargetNamespace();
            
            System.out.println(targetNameSpace);
            System.out.println(methodd);
            System.out.println(r);*/
            try {
                String endpoint = ars[0];//"http://lyricwiki.org/server.php"; //ars[0];
                Service service = new Service();
                Call call = (Call) service.createCall();
                call.setEncodingStyle(Constants.NS_URI_SOAP_ENC);
                call.setSOAPActionURI("urn:LyricWiki#getHometown");
                //call.setUseSOAPAction(true);
                //call.setProperty(call.SEND_TYPE_ATTR, Boolean.FALSE);
                //call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
                //call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
                //call.setProperty( Call.SOAPACTION_USE_PROPERTY, new Boolean( true ) );
                //call.setProperty( Call.SOAPACTION_URI_PROPERTY, "http://www.west-wind.com/foxcentral/GetNewsItems");
                call.setTargetEndpointAddress(new java.net.URL(endpoint));
                call.setOperationName(new QName("urn:LyricWiki", ars[1]));
                call.addParameter("artist", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN);
                //call.addParameter("parameters", org.apache.axis.Constants.XSD_INTEGER,
                //     ParameterMode.IN);
                //call.addParameter("parameters", org.apache.axis.Constants.XSD_QNAME,
                //     ParameterMode.IN);
                call.setReturnType(org.apache.axis.Constants.XSD_STRING);
                Object ret = call.invoke(new Object[]{ars[2]});
                System.out.println(ret);
            } catch (Exception e) {
                System.err.println(e.toString());
            }
    } catch (WSDLException ex) {
            Logger.getLogger(externalWS.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
    


}
