###1、将wsdl文件导入WEB-INF ###2、导入jaxws-ri的包 ###3、在WEB-INF目录下创建sun-jaxws.xml
###4、创建web.xml
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
但是访问qyyx_01成功, 为什么?
注意是通过url,而不是wsdl文件生成的
\JavaWeb\qyyx_02_tomcat_client\src>wsimport -d .\ -keep -verbose http://localhost:8080/qyyx_02_tomcat/us?wsdl
package com.chb.service.client;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import org.junit.Before;
import org.junit.Test;
import com.chb.service.IUserService;
import com.chb.service.User;
import com.chb.service.UserException_Exception;
import com.chb.service.UserService;
/**
* wsimport -d G:\JavaWeb\qyyx_01_client\src -verbose -keep http://localhost:9999/us?wsdl
*/
public class MyClient {
private IUserService iMyService;
@Before
public void init() throws MalformedURLException {
//创建访问的URL
URL url = new URL("http://10.255.40.120:8080/qyyx_02_tomcat/us?wsdl");
QName qName = new QName("http://service.chb.com/", "UserService");
UserService msis = new UserService(url, qName);
//获取IMyService, 简单多了
iMyService = msis.getUserServicePort();
}
@Test
public void testAdd() {
User user = new User();
user.setUsername("wx");
user.setNickname("wuxin");
user.setPassword("111");
try {
iMyService.add(user);
} catch (UserException_Exception e) {
e.printStackTrace();
}
}
@Test
public void testList() {
for (User u : iMyService.list()) {
System.out.println(u);
}
}
@Test
public void testLogin() {
try {
System.out.println(iMyService.login("chb", "123456"));
} catch (UserException_Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}