XFire 是新一代 Java SOAP Web Services 框架,基於 Aegis 數據綁定,輕量級、高性能、易集成。本文以 Eclipse + Tomcat 環境為例,演示從項目配置、服務定義到發布驗證的完整流程。
aegis、wstx、xmlschema、commons-codec 等)
XFireServlet
org.codehaus.xfire.transport.http.XFireConfigurableServlet
0
XFireServlet
/services/*
// 接口
package com.xaccp.service;
public interface HelloService {
String sayHello(String name);
}
// 實現
package com.xaccp.service;
public class HelloServiceImpl implements HelloService {
public String sayHello(String name) {
System.out.println("來自客戶端的用戶:" + name);
return "服務器說你好:" + name;
}
}
在 Eclipse 中:右鍵項目 → Properties → XFire → 添加服務類 → 選擇 HelloServiceImpl → 服務名稱 HelloService → 完成。

發布服務向導

服務配置確認
XFire 會在 src/META-INF/xfire/services.xml 自動生成:
HelloService
https://service.xaccp.com
com.xaccp.service.HelloService
com.xaccp.service.HelloServiceImpl
application
https://localhost:8080/your-project/services/HelloService?wsdl// 使用 XFire 客戶端 API
Service service = new ObjectServiceFactory().create(HelloService.class);
HelloService client = (HelloService) new XFireProxyFactory().create(service, "https://localhost:8080/project/services/HelloService");
String result = client.sayHello("張三");
System.out.println(result); // 輸出:服務器說你好:張三
xfire-spring 模塊,在 Spring XML 中聲明 <xfire:service>WSSecurityInInterceptor/OutInterceptor 實現簽名加密binding.setMTOMEnabled(true)XFire 專案已停止維護(最後版本 2009 年),新項目請選用 Apache CXF 或 Spring Boot + JAX-WS/CXF,獲得長期支持與現代特性(REST、JSON、Reactive)。