Xfire simple Webservices to implement and call

一、易出現問題地方,Jar缺乏或衝突 java

XFire使得在JavaEE應用中發佈Web服務變得垂手可得。和其餘Web服務引擎相比,
XFire的配置很是簡單,能夠很是容易地和Spring集成。
下載地址:http://xfire.codehaus.org/Download 可是jar很容易出錯,我試了好久才成功網上雖然不少實例可是照着作也不容易成功主要是jar致使的失敗讓人頗有挫敗感,因此在此總結貼出比較多的Jar(有些jar未用到,可是建議保留)。 web

二、開發項目目錄Jars 瀏覽器

 

 

三、建立webservice藉口 app

package com.boonya.xfire.ws;

public interface IUserServices {
	
	public String sayHello(String message);
	
}
四、 實現 webservice接口
package com.boonya.xfire.ws;

public class UserServicesImpl implements IUserServices {
	
	public String sayHello(String message) {
		System.out.println(message);
		return message; 
	}
	
}
五、 編寫 代理 客戶端 測試
package com.boonya.xfire.ws;

import java.net.MalformedURLException;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public class UserTestClient {

	public static void main(String[] args) throws MalformedURLException {
		Service service = new ObjectServiceFactory()
				.create(IUserServices.class);
		XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
				.newInstance().getXFire());
		String url = "http://localhost:8080/myws/services/UserServices";
		IUserServices userService = (IUserServices) factory.create(
				service, url);
		String res = userService.sayHello("Hello boonya ,you singned sucess!");
		System.out.println(res);

	}

}
六、 src 目錄 建立META-INF, 下面 建立 xfire 文件夾, 並在 xfire 文件夾 建立 services. xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">

	<service>
		<name>UserServices</name>
		<namespace>http://ws.com</namespace>
		<serviceClass>com.boonya.xfire.ws.IUserServices</serviceClass>
		<implementationClass>com.boonya.xfire.ws.UserServicesImpl</implementationClass>
		<style>wrapped</style>
		<use>literal</use>
		<scope>application</scope>
	</service>
</beans>
七、 配置 xfire web.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>XFireServlet</servlet-name>
    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>XFireServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
八、 myw s 加入 Tomcat 容器, 部署 啓動

在瀏覽器輸入以下內容訪問 jsp


客戶端後臺代理測試結果以下: 測試

相關文章
相關標籤/搜索