Use xfire to done your web services in java

本文介绍如何使用XFIRE搭建WebService及客户端调用流程。通过配置xfire-servlet.xml和web.xml,实现服务端发布WebService,并展示如何在客户端进行调用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Use xfire to done your web services

1.  Sample

Service:

First config, xfire-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

    <!-- URLs to WebService mapping. Requests are forwarded through Springs' DispatcherServlet -->

    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

        <property name="urlMap">

            <map>

                <entry key="/BankInterface">

                    <ref bean="bank[j1] "/>

                </entry>

//映射到URLKEY

            </map>

        </property>

    </bean>

 

    <!-- Declare a parent bean with all properties common to both services -->

    <bean id="bank" class="org.codehaus.xfire.spring.remoting.XFireExporter">

        <property name="serviceFactory">

            <ref bean="xfire.serviceFactory"/>

        </property>

        <property name="xfire">

            <ref bean="xfire"/>

        </property>

        <property name="serviceBean">

            <ref bean="bankInterfaceService[j2] "/>

        </property>

        <property name="serviceClass">

            <value>com.fch.fps.bs.bankinterface.BankInterface[j3] </value>

        </property>

//映射SERVICE

    </bean>

</beans>

THEN,WEB.XML:

<context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>

classpath:/com/fch/fps/bs/spring/applicationContext.xml

            classpath:org/codehaus/xfire/spring/xfire.xml

        </param-value>

</context-param>

 

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

 

<servlet>

        <servlet-name>xfire</servlet-name>

   <servlet-class>org.springframework.web.servlet.DispatcherServlet

</servlet-class>

</servlet>

 

<servlet-mapping>

        <servlet-name>xfire</servlet-name>

        <url-pattern>/ws/*</url-pattern>

</servlet-mapping>

 

这样启动服务,写 http://localhost:7001/配置工程名/ws/BankInterface 就可以看到,加上 WSDL 就可解析为XML

 

假如SERVICE1方法“public void register()”,需要被CLIENT调用.

 

2.  CLIENT

Just need few word like this:

 

import org.codehaus.xfire.client.XFireProxyFactory;

import org.codehaus.xfire.service.Service;

import org.codehaus.xfire.service.binding.ObjectServiceFactory;

Service ser=new ObjectServiceFactory().

Create(BankInterfaceService.class);

//xfire-servlet.xml中的接口 serviceBean

 

BankInterfaceService bankser=( BankInterfaceService)

new xfireproxyFactory.create(ser,url);

//this  url must be http://localhost:7001/配置工程名/ws/BankInterface

 

Ok,now “bankser” can do whatever u want

 

Bankser.register();


 [j1]The same as the “<bean id=”bank”. . . . . . . “

 [j2]Spring 配置文件中注入的service

 [j3]Service的接口

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值