XFire WebService 发布与调用

                                         创建webservices服务

 

第一步

 

添加架包

 

第二步

 

web.xml文件添加过滤器

<filter>
        <filter-name>webservicefilter</filter-name>
        <filter-class>com.sungoal.webservice.WebserviceFilter</filter-class>
</filter>

<filter-mapping>
        <filter-name>webservicefilter</filter-name>
        <url-pattern>/services/*</url-pattern>

</filter-mapping>

 

 

第三步

 

添加services.xml文件,目录格式如下: /Caesar3_standard/src/META-INF/xfire/services.xml

 

第四步

 

编写接口与实现类

 

第五步

 

在services.xml 文件中配置节点,程序发布的时候会读取这个文件生成发布内容

<beans>
    <service xmlns="http://xfire.codehaus.org/config/1.0">
    <name>ResultService</name>
    <namespace>http://192.168.12.112/services/ResultService</namespace>
    <serviceClass>com.sungoal.webservice.IResultService</serviceClass>
    <implementationClass>com.sungoal.webservice.ResultService</implementationClass>
  </service>

</beans>

 

 

 

 

客户端

 

调用方法一

 

 

package com.sungoal.DeleteIndex;


import java.net.MalformedURLException;

import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public class test {

   
    public static void main(String[] args) {
        String serviceUrl = "http://localhost//services/DeleteIndexService";
        Service serviceModel = new ObjectServiceFactory().create(I_DeleteIndexService.class, null, serviceUrl, null);
        XFireProxyFactory serviceFactory = new XFireProxyFactory();
        try {
            I_DeleteIndexService service = (I_DeleteIndexService)serviceFactory.create(serviceModel,serviceUrl);
            boolean is = service.deleteIndex("aaa","id", new String[]{"1"});
            //System.out.println(is);
           
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
       
    }
   
}

 

(注:服务发布者需要复制 发布的接口类 给客户端调用方,不太方便)

 

调用方法二

 

package com.sungoal.DeleteIndex;

import java.net.MalformedURLException;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class test2 {
   
    public static void main(String[] args) {
        String serviceURL = "http://localhost//services/DeleteIndexService";
        Service service = new Service();
        Call call;
        try {
           
            call = (Call) service.createCall();
            call.setTargetEndpointAddress(new java.net.URL(serviceURL));
            call.setOperationName("deleteIndex");
            Object is = call.invoke(new Object[]{"aaa","ddd_ss_ss",new String[]{"asas_sd_kjh","sdfsdf_sdd_sd"}});
           
            //System.out.println(is);
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
       
    }

}

 

你可能感兴趣的:(webservice,xfire)