webservice的使用
1,首先建立服务端程序,以便发布
(1)打开myeclipse建立一个webservice project
命名为:xfire
勾选xfire-next-next--勾选前面三个包
一个客服端webservice project程序建立成功
(2)建立相关的接口,类
package com.impl;
import java.util.ArrayList;
import com.UserInfo;
import com.WebServiceInterface;
public class WebServiceImpl implements WebServiceInterface {
public String getMessage(String us) {
// TODO Auto-generated method stub
System.out.println("服务器端getMessage方法 你来了"+us);
return "Hello "+us;
}
public UserInfo getUserInfo(){
UserInfo uf = new UserInfo("yanther","1001",30);
return uf;
}
public ArrayList<UserInfo> getAllUser(){
ArrayList<UserInfo> alluser= new ArrayList<UserInfo>();
UserInfo uf = new UserInfo("yanther","1001",30);
UserInfo uc = new UserInfo("yang","1002",10);
UserInfo ux = new UserInfo("yxj","10013",18);
alluser.add(uf);
alluser.add(uc);
alluser.add(ux);
return alluser;
}
}
================================================
package com;
import java.util.ArrayList;
public interface WebServiceInterface {
/**
*
* @param us
* @return
*/
public String getMessage(String us);
/**
*
* @return
*/
public UserInfo getUserInfo();
/**
*
* @return
*/
public ArrayList<UserInfo> getAllUser();
}
================================================
package com;
public class UserInfo {
private String userName;
private String userCode;
private int userAge;
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return the userCode
*/
public String getUserCode() {
return userCode;
}
/**
* @param userCode the userCode to set
*/
public void setUserCode(String userCode) {
this.userCode = userCode;
}
/**
* @return the userAge
*/
public int getUserAge() {
return userAge;
}
/**
* @param userAge the userAge to set
*/
public void setUserAge(int userAge) {
this.userAge = userAge;
}
/**
* @param userName
* @param userCode
* @param userAge
*/
public UserInfo(String userName, String userCode, int userAge) {
this.userName = userName;
this.userCode = userCode;
this.userAge = userAge;
}
}
=================================================
(3)对service.xml进行配置
如: <?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>websTest</name>
<namespace>yidu.t40</namespace>
<serviceClass>com.WebServiceInterface</serviceClass>
<implementationClass>com.impl.WebServiceImpl</implementationClass>
</service>
</beans>
(4)http://localhost:8989/xfire/websTest进行发布
连接的有个wsdl结尾的路径拷贝下来
---------------------------------
2,客服端的应用
(1)和上面类同建立一个webservice project
(2)点击工程src-new-other-webservice-webserviceclient
填入发布的那个路径就可以用到发布的相关方法和类了
-------------------------------
更详细解释的网站:http://blog.csdn.net/yxpjx/archive/2010/10/22/5959064.aspx