开发客户端程序有两种,一种自己手写,还有是用工具通过wsdl来自动生成client 我是手写的,比如: Service serviceModel = new ObjectServiceFactory(new AegisBindingProvider()) .create(MathService.class); "http://localhost:8080/xfire/MathService.soap"); System.out.println(service.add(10, 20));
上面的代码不小心漏掉了一部分,现在补全我自己现在也有个问题,当方法参数是JavaBean该怎么处理,我写了配置文件MathService.aegis.xml,但是好像没有用,不知楼主这个问题解决了没有 Service serviceModel = new ObjectServiceFactory(new AegisBindingProvider()) .create(MathService.class); MathService service = (MathService) new XFireProxyFactory().create( serviceModel, "http://localhost:8080/xfire/MathService.soap"); System.out.println(service.add(10, 20));
Service serviceModel = new ObjectServiceFactory(new AegisBindingProvider()) .create(MathService.class);MathService service = (MathService) new XFireProxyFactory().create( serviceModel, "http://localhost:8080/xfire/MathService.soap");System.out.println(service.add(10, 20)); 这是客户端的代码? 我客户端调用web服务的时候,本地根本不能得到MathService.class这个类的! 实际上是这样: 把开发好的一个web服务放到一台服务器上,在另一台机器上开发一个客户端去调用这个web服务,之后再作一些后续的处理!!!
客户端代码:Service helloServiceModel = new ObjectServiceFactory().create(HelloService.class); HelloService hello = (HelloService) new XFireProxyFactory().create(helloServiceModel, "http://localhost:8080/xfire/HelloService.soap"); Employee e = new Employee(); e.setEmployeeName("jeff"); //原来的代码:System.out.println(hello.sayHelloBean(new Employee("jeffrey")); System.out.println(hello.sayHelloBean(e));我原来的问题已经被我老大解决了,原来我写的JavaBean有问题,Employee里我把默认构造方法给去掉了,就不是一个JavaBean因此无法传输
web service无所谓在哪个服务器上,客户端只要知道服务器的url就可以了 在例子里就是http://localhost:8080/......本地客户端需要知道你所要调用的Service的接口,然后xfire用这些接口来作动态代理,得到运行期的Service,就好像在本地调用一样。如果你用过apache soap就知道写客户端代码有多么烦,只有自己来写一个soap的动态代理的包装类,在xfire里已经为你完成一切了,just need: Service helloServiceModel = new ObjectServiceFactory().create(HelloService.class); HelloService hello = (HelloService) new XFireProxyFactory().create(helloServiceModel, "http://localhost:8080/xfire/HelloService.soap");
Service mathServiceModel = new ObjectServiceFactory().create(MathService.class); MathService math = (MathService) new XFireProxyFactory().create(mathServiceModel, "http://localhost:8080/XfireSpring/MathService"); System.out.println(math.add(1, 2)); // should print 3 具体类所在位置请查api
大家多交流交流
http://www.javaresearch.org/article/column.jsp?column=5
里面的
<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask"
classpathref="xfire ¨ jar ©lª " />
<wsgen outputDirectory="client" wsdl="MathService.
package="com.kuaff.xfire.samples" />
不知道该写到那块?
不知怎样开发客户端程序?
大家继续!!!
我是手写的,比如:
Service serviceModel = new ObjectServiceFactory(new AegisBindingProvider())
.create(MathService.class);
"http://localhost:8080/xfire/MathService.soap");
System.out.println(service.add(10, 20));
Service serviceModel = new ObjectServiceFactory(new AegisBindingProvider())
.create(MathService.class); MathService service = (MathService) new XFireProxyFactory().create(
serviceModel, "http://localhost:8080/xfire/MathService.soap"); System.out.println(service.add(10, 20));
十分感激你的回复!
我刚接触xfire,以前都是用axis来开发webservice
我现在只做到了这一步:
就是web服务可以发布成功,现在想开发个客户端程序来调用这个web服务,不知道怎么继续下去!可否把你的源码发给我借鉴一下!十分感谢!
是一个配置文件?
多谢了!
把开发好的一个web服务放到一台服务器上,在另一台机器上开发一个客户端去调用这个web服务,之后再作一些后续的处理!!!
大哥求你了!
行行好了!
//不能用,目前还没配置好传递JavaBean
//public abstract String sayHelloBean(Employee name);}HelloServiceImpl.java
package xfire;public class HelloServiceImpl implements HelloService {
public String sayHello(String name) {
return "Hello, " + name;
} //public String sayHelloBean(Employee name) {
// return "Hello, " + name;
//}
}applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="helloBean" class="xfire.HelloServiceImpl" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/HelloService.soap">
<ref bean="hello" />
</entry>
</map>
</property>
</bean> <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" abstract="true">
<property name="serviceFactory">
<ref bean="xfire.serviceFactory" />
</property>
<property name="xfire">
<ref bean="xfire" />
</property>
</bean>
<bean id="math" parent="baseWebService">
<property name="serviceBean">
<ref bean="mathBean" />
</property>
<property name="serviceClass">
<value>xfire.MathService</value>
</property>
</bean>
<bean id="hello" parent="baseWebService">
<property name="serviceBean">
<ref bean="helloBean" />
</property>
<property name="serviceClass">
<value>xfire.HelloService</value>
</property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- START SNIPPET: xfire -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param> <context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param> <listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener> <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>*.soap</url-pattern>
</servlet-mapping>
<!-- END SNIPPET: xfire -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>
.create(MathService.class);MathService service = (MathService) new XFireProxyFactory().create(
serviceModel, "http://localhost:8080/xfire/MathService.soap");System.out.println(service.add(10, 20));
这是客户端的代码?
我客户端调用web服务的时候,本地根本不能得到MathService.class这个类的!
实际上是这样:
把开发好的一个web服务放到一台服务器上,在另一台机器上开发一个客户端去调用这个web服务,之后再作一些后续的处理!!!
HelloService hello = (HelloService) new XFireProxyFactory().create(helloServiceModel, "http://localhost:8080/xfire/HelloService.soap");
Employee e = new Employee();
e.setEmployeeName("jeff");
//原来的代码:System.out.println(hello.sayHelloBean(new Employee("jeffrey"));
System.out.println(hello.sayHelloBean(e));我原来的问题已经被我老大解决了,原来我写的JavaBean有问题,Employee里我把默认构造方法给去掉了,就不是一个JavaBean因此无法传输
http://localhost:8080/XfireSpring/MathService这样?我这么调用提示我:Invalid SOAP request.
不知何解?
在例子里就是http://localhost:8080/......本地客户端需要知道你所要调用的Service的接口,然后xfire用这些接口来作动态代理,得到运行期的Service,就好像在本地调用一样。如果你用过apache soap就知道写客户端代码有多么烦,只有自己来写一个soap的动态代理的包装类,在xfire里已经为你完成一切了,just need:
Service helloServiceModel = new ObjectServiceFactory().create(HelloService.class);
HelloService hello = (HelloService) new XFireProxyFactory().create(helloServiceModel, "http://localhost:8080/xfire/HelloService.soap");
在浏览器上你怎么调用web服务?
http://localhost:8080/XfireSpring/MathService这样?我这么调用提示我:Invalid SOAP request.
不知何解?---------------------------------------------Invalid SOAP request.这表示你已经能够访问了,配置是没有问题的
你可以试试看:http://localhost:8080/XfireSpring/MathService?wsdl
如果你能看到xml文件,配置肯定是没有问题的SOAP是给客户端访问的不是浏览器
兄弟!
有啥好学习资料给整点!
我叫姚立锋!---------------
:)
XFire 的资料真的非常少,这是一个非常新的SOAP框架,号称“下一代”,别说中文的,英文的都没有什么资料。我在TTS的web services/xml论坛里也没找到什么英文的:
<Webservices with Spring, XFire and jsr181>
http://www.logemann.org/blojsom/blog/default/?permalink=Webservices-with-Spring-XFire-and-jsr181.htmlAppFuse有关xfire和spring集成的文章
http://raibledesigns.com/wiki/Wiki.jsp?page=AppFuseXFire#ref-AppFuseXFire-2中文的:
SpringSide有关Xfire的介绍:(你可以下载SpringSide的源代码参考一下)
http://www.springside.org.cn/docs/reference/XFire.htm
http://localhost:8080/XfireSpring/MathService
MathService math = (MathService) new XFireProxyFactory().create(mathServiceModel, "http://localhost:8080/XfireSpring/MathService");
System.out.println(math.add(1, 2)); // should print 3
具体类所在位置请查api
远程调用我这个服务的时候,比如说你现在要调用我的服务,你那面应该怎么做?
MathService.class这个类你那边根本没有,我只能给你提供一个“http://localhost:8080/XfireSpring/MathService”你怎么来调用我这个服务???
呵呵!我还是有点郁闷
你也可以自己写一个包装类进一步的简化客户端代码