webservice的使用

1,首先建立服务端程序,以便发布

(1)打开myeclipse建立一个webserviceproject

命名为:xfire

勾选xfire-next-next--勾选前面三个包

一个客服端webserviceproject程序建立成功

(2)建立相关的接口,类

packagecom.impl;

importjava.util.ArrayList;

importcom.UserInfo;

importcom.WebServiceInterface;

publicclassWebServiceImplimplementsWebServiceInterface{

publicStringgetMessage(Stringus){

//TODOAuto-generatedmethodstub

System.out.println("服务器端getMessage方法你来了"+us);

return"Hello"+us;

}

publicUserInfogetUserInfo(){

UserInfouf=newUserInfo("yanther","1001",30);

returnuf;

}

publicArrayList<UserInfo>getAllUser(){

ArrayList<UserInfo>alluser=newArrayList<UserInfo>();

UserInfouf=newUserInfo("yanther","1001",30);

UserInfouc=newUserInfo("yang","1002",10);

UserInfoux=newUserInfo("yxj","10013",18);

alluser.add(uf);

alluser.add(uc);

alluser.add(ux);

returnalluser;

}

}

================================================

packagecom;

importjava.util.ArrayList;

publicinterfaceWebServiceInterface{

/**

*

*@paramus

*@return

*/

publicStringgetMessage(Stringus);

/**

*

*@return

*/

publicUserInfogetUserInfo();

/**

*

*@return

*/

publicArrayList<UserInfo>getAllUser();

}

================================================

packagecom;

publicclassUserInfo{

privateStringuserName;

privateStringuserCode;

privateintuserAge;

/**

*@returntheuserName

*/

publicStringgetUserName(){

returnuserName;

}

/**

*@paramuserNametheuserNametoset

*/

publicvoidsetUserName(StringuserName){

this.userName=userName;

}

/**

*@returntheuserCode

*/

publicStringgetUserCode(){

returnuserCode;

}

/**

*@paramuserCodetheuserCodetoset

*/

publicvoidsetUserCode(StringuserCode){

this.userCode=userCode;

}

/**

*@returntheuserAge

*/

publicintgetUserAge(){

returnuserAge;

}

/**

*@paramuserAgetheuserAgetoset

*/

publicvoidsetUserAge(intuserAge){

this.userAge=userAge;

}

/**

*@paramuserName

*@paramuserCode

*@paramuserAge

*/

publicUserInfo(StringuserName,StringuserCode,intuserAge){

this.userName=userName;

this.userCode=userCode;

this.userAge=userAge;

}

}

=================================================

(3)对service.xml进行配置

如:<?xmlversion="1.0"encoding="UTF-8"?>

<beansxmlns="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)和上面类同建立一个webserviceproject

(2)点击工程src-new-other-webservice-webserviceclient

填入发布的那个路径就可以用到发布的相关方法和类了

-------------------------------------------------------------------

更详细解释的网站:http://blog.csdn.net/yxpjx/archive/2010/10/22/5959064.aspx

相关推荐