package com.mybank.xfire.example;
public interface IBankingService
{
public String transferFunds(String fromAccount,String toAccount,
double amount, String currency);
}
package com.mybank.xfire.example;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class BankingService implements IBankingService
{
public BankingService() { };
public String transferFunds(String fromAccount, String toAccount,double amount, String currency)
{
String statusMessage = "";
try
{
NumberFormat formatter = new DecimalFormat("###,###,###,###.00");
statusMessage = "COMPLETED: " + currency + " " + formatter.format(amount)
+ " was successfully transferred from A/C# " + fromAccount + " to A/C# " + toAccount;
}
catch (Exception e)
{
statusMessage = "BankingService.transferFunds(): EXCEPTION: " + e.toString();
}
return statusMessage;
}
}
<?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>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/servlet/XFireServlet/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>Banking</name>
<namespace>mybank</namespace>
<serviceClass>
com.mybank.xfire.example.IBankingService
</serviceClass>
<implementationClass>
com.mybank.xfire.example.BankingService
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service>
</beans>
package com.mybank.xfire.example;
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 client
{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Service srvcModel = new ObjectServiceFactory()
.create(IBankingService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String helloWorldURL = "http://localhost:8080/test/services/Banking";
try
{
IBankingService srvc = (IBankingService) factory.create(srvcModel, helloWorldURL);
System.out.print(srvc.transferFunds("张三", "李四", 10000, "清理欠款"));
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
}