java 调用 web service

Invoking web services with Java clients
http://www.ibm.com/developerworks/webservices/library/ws-javaclient/index.html#listing4


/*
 * DynamicProxy class
 * J2SE unamanaged client
 * Service lookup: JAX-RPC ServiceFactory
 * Service access: Dynamic Proxy
 */

import java.net.URL;

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

public class DynamicProxy {

	public interface HelloInterface {

		char[] getGreeting(String string);

	}

	public static void main(String[] args) {
		String wsdlURL = "http://localhost:6080/Sample2WebService/services/Sample2?wsdl";
		String namespace = "http://Sample2.wsdk.ibm.com";
		String serviceName = "HelloInterfaceService";
		String portName = "Sample2";

		try {

			/* Service lookup */
			ServiceFactory serviceFactory = ServiceFactory.newInstance();
			Service sampleService = serviceFactory.createService(new URL(
					wsdlURL), new QName(namespace, serviceName));

			/* Service access */
			HelloInterface myProxy = (HelloInterface) sampleService.getPort(
					new QName(namespace, portName), HelloInterface.class);

			/* Service invocation */
			System.out.println(myProxy.getGreeting(args[0]));

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

你可能感兴趣的:(java,Web,xml,J2SE,IBM)