用XFire成功发布WebService
2011-05-26 17:20
253 查看
发布WebService之前必须在项目中添加XFire *.* Core Libraies和XFire *.* HTTP Client Libraries(从MyEclipse中的Java Build Path中获取),下面以HelloWorld为例发布WEB服务。
--------------[b]---------------------------------------source: interface begin------------------------------------------------------[/b]
package com.sun.java;
public interface IHelloWorldService {
public String example1(String message);
}
-----------[b]-----------------------------------------source: interface impl begin--------------------------------------------------[/b]
package com.sun.java;
public class HelloWorldServiceImpl implements IHelloWorldService {
public String example1(String message) {
return message;
}
}
----------------[b]-----------------------------------------配置: web.xml begin------------------------------------------------------[/b]
<?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>
</web-app>
--------------------[b]-------------------------------------配置: services.xml
begin------------------------------------------------[/b]
services.xml文件在Eclipse中的路径为WebContent/WEB-INF/classes/META-INF/xfire/services.xml,在MyEclipse中的路径为WebRoot/WebServices/services.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>HelloWorldService</name>
<serviceClass>com.sun.java.IHelloWorldService</serviceClass>
<implementationClass>com.sun.java.HelloWorldServiceImpl</implementationClass>
</service>
</beans>
-------------------------[b]-------------------------------客户端: 部署测试 begin---------------------------------------------------
[/b]package com.sun.java.client;
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;
import com.sun.java.IHelloWorldService;
public class HelloWorldClient {
//方法1
public static void main(String[] args) {
HelloWorldServiceClient client = new HelloWorldServiceClient();
//create a default service endpoint
HelloWorldServicePortType service = client.getHelloWorldServiceHttpPort();
//Add custom client code here
service.example1("hello world");
System.out.println("test client completed");
}
//方法2
public static void main(String[] args) {
Service srvcModel = new ObjectServiceFactory().create(IHelloWorldService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
//发布URL如下,对应的WS描述语言为:http://localhost/HelloWorld/services/HelloWorldService?wsdl
String helloWorldURL = "http://localhost/HelloWorld/services/HelloWorldService";
try {
IHelloWorldService srvc = (IHelloWorldService) factory.create(srvcModel, helloWorldURL);
String result = srvc.example1("hello world");
System.out.print(result);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
--------------[b]---------------------------------------source: interface begin------------------------------------------------------[/b]
package com.sun.java;
public interface IHelloWorldService {
public String example1(String message);
}
-----------[b]-----------------------------------------source: interface impl begin--------------------------------------------------[/b]
package com.sun.java;
public class HelloWorldServiceImpl implements IHelloWorldService {
public String example1(String message) {
return message;
}
}
----------------[b]-----------------------------------------配置: web.xml begin------------------------------------------------------[/b]
<?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>
</web-app>
--------------------[b]-------------------------------------配置: services.xml
begin------------------------------------------------[/b]
services.xml文件在Eclipse中的路径为WebContent/WEB-INF/classes/META-INF/xfire/services.xml,在MyEclipse中的路径为WebRoot/WebServices/services.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>HelloWorldService</name>
<serviceClass>com.sun.java.IHelloWorldService</serviceClass>
<implementationClass>com.sun.java.HelloWorldServiceImpl</implementationClass>
</service>
</beans>
-------------------------[b]-------------------------------客户端: 部署测试 begin---------------------------------------------------
[/b]package com.sun.java.client;
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;
import com.sun.java.IHelloWorldService;
public class HelloWorldClient {
//方法1
public static void main(String[] args) {
HelloWorldServiceClient client = new HelloWorldServiceClient();
//create a default service endpoint
HelloWorldServicePortType service = client.getHelloWorldServiceHttpPort();
//Add custom client code here
service.example1("hello world");
System.out.println("test client completed");
}
//方法2
public static void main(String[] args) {
Service srvcModel = new ObjectServiceFactory().create(IHelloWorldService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
//发布URL如下,对应的WS描述语言为:http://localhost/HelloWorld/services/HelloWorldService?wsdl
String helloWorldURL = "http://localhost/HelloWorld/services/HelloWorldService";
try {
IHelloWorldService srvc = (IHelloWorldService) factory.create(srvcModel, helloWorldURL);
String result = srvc.example1("hello world");
System.out.print(result);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
相关文章推荐
- (2)使用XFire方式发布WebService实例说明
- xfire发布webservice
- java程序调用xfire发布的webService服务
- java程序调用xfire发布的webService服务(二)
- .net调用java xfire发布的webservice封装soapheader头信息
- .net C# 调用 XFire发布的Webservice 安全访问控制
- xfire发布webservice
- 使用xfire快速发布WebService接口
- webservice发布问题,部署iis后调用不成功
- xfire发布的Webservice中Spring注入为空的解决方案
- Spring中整合Xfire发布webservice服务
- Webservice使用xfire发布及客户端调用
- WebService 发布不成功,显示无法找到该页错误 404的解决方法
- [转载]WebService 发布不成功,显示无法找到该页错误 404的解决方法
- .net C# 调用 XFire发布的Webservice 安全访问控制
- 三、取消发布的WebService(删除一个发布成功的Web服务)
- xfire发布webservice
- axis2 调用webService(包含用axis2和xfire发布的)实例,加注释
- 使用xfire快速发布WebService接口
- 发布简单的webservice xfire