用java sdk 写webservice

添加文件 user.properties

 

wsdl=http://localhost:9090/cxfspring/services/HelloWorld?wsdl
name=http://server.hw.demo/
webservice=HelloWorldImplService

 

添加webservice 通过wsimport 生成后的

 

package com.test.client;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.logging.Logger;

import javax.xml.namespace.QName;

/**
 * 
 * @author liuqing
 *
 */
public class Client {
	private final static URL USERWEBSERVICESERVICE_WSDL_LOCATION;
	private final static Logger logger = Logger.getLogger(Client.class.getName());
	
	private static Properties ps = new Properties();
	
	static {
		try {
			ps.load(Client.class.getResourceAsStream("/com/test/user.properties"));
		} 
		catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	static URL url = null;
	static {
        try {
            URL baseUrl;
            baseUrl = Client.class.getResource(".");
            url = new URL(baseUrl, ps.getProperty("wsdl"));
        } catch (MalformedURLException e) {
            logger.warning("Failed to create URL for the wsdl Location: 'http://localhost:7777/usb/userinfoes/UserWebService?wsdl', retrying as a local file");
            logger.warning(e.getMessage());
        }
        USERWEBSERVICESERVICE_WSDL_LOCATION = url;
    }
	
	public static void main(String args[]) {
		HelloWorld us = new 
		HelloWorldImplService(url,new QName(ps.getProperty("name")
				, ps.getProperty("webservice"))).getHelloWorldImplPort();
		System.out.println(us.sayHello(" hello I'm Client !"));
	}

}

 

你可能感兴趣的:(java,.net,xml,webservice)