Web Service修炼之一XFire入门3

5、运行测试应用

    启动Tomcat
    再打开浏览器,输入:http://localhost:8080/ws/services

    服务器返回的结果如下:
 
WebService已经布署成功了,打开WSDL信息:

    http://localhost:8080/ws/services/SayHelloService?wsdl

    其中 sayHelloService是配置文件中 service\name 元素所定义的内容,”wsdl”参数表示查看该 Web 服务的 WSDLWeb服务描述语言)文件。

 

    注意:XML的空格或者有些字符在不同的编码下,会出现乱码,到时XML解析会出错。我这边运行这个servers.xml实例,由于编码不符合UTF-8,配置内容是其他编码形式,导致 XML解析报错:

org.springframework.beans.factory.BeanCreationException

Error creating bean with name 

'org.codehaus.xfire.spring.ServiceBean' defined in class path 

resource [META-INF/xfire/services.xml]: Error setting property 

values; nested exception is 

org.springframework.beans.NotWritablePropertyException: I

nvalid property '????' of bean class 

[org.codehaus.xfire.spring.ServiceBean]: 

Bean property '????' is not writable or has an invalid setter 

method: Does the parameter type of the setter match the return 

type of the getter?

org.springframework.beans.NotWritablePropertyException

Invalid property '????' of bean class 

[org.codehaus.xfire.spring.ServiceBean]: 

Bean property '????' is not writable or has an invalid 

setter method: Does the parameter type of the setter 

match the return type of the getter?

6模拟远程调用

    客户端Java代码 

  package com.test.ws;

import java.net.MalformedURLException;

import org.codehaus.xfire.client.Client;

import org.codehaus.xfire.client.XFireProxyFactory;

import org.codehaus.xfire.service.Service;

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

import org.codehaus.xfire.transport.http.CommonsHttpMessageSender;

public class SayHelloClient {

public static void main(String args[]) { 

String serviceURL = "http://localhost:8080/ws/services/SayHelloService"

//创建service对象

Service serviceModel = new ObjectServiceFactory().create(SayHelloService.class); 

XFireProxyFactory serviceFactory = new XFireProxyFactory(); 

try

//获取服务对象

SayHelloService service = (SayHelloService) serviceFactory.create(serviceModel, serviceURL); 

Client client = Client.getInstance(service); 

//忽略http连接的超时时间,0为不设置超时时间,》=1为超时毫秒数

client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT"0"); 

String msg = service.sayHello("大兵"); 

System.out.println("服务器对[大兵]的回复:" +  msg); 

 msg = service.sayHello(null); 

System.out.println("服务器对的回复:" +  msg); 

}catch (MalformedURLException e) { 

    e.printStackTrace();

}

   } 

 客户端运行结果:

    服务器对[大兵]的回复:大兵,早上好,还没有去工作吗 ?

    服务器对你的回复:你叫什么名字呢?

注意:当客户端设置http连接超时为1毫秒时

Client client = Client.getInstance(service);

client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "1");

会出现如下错误提示:

2013-9-12 11:21:02 org.codehaus.xfire.transport.http.HttpChannel

 sendViaClient

严重: java.net.SocketTimeoutException: Read timed out

Exception in thread "main" 

org.codehaus.xfire.XFireRuntimeException

Could not invoke service.. 

Nested exception is org.codehaus.xfire.fault.XFireFault: 

Couldn't send message.

org.codehaus.xfire.fault.XFireFault: Couldn't send message.

at org.codehaus.xfire.fault.XFireFault.createFault

(XFireFault.java:89)

at org.codehaus.xfire.handler.OutMessageSender.invoke

(OutMessageSender.java:30)

at org.codehaus.xfire.handler.HandlerPipeline.invoke

(HandlerPipeline.java:13

 

  

    从例子实现的过程中,我们可以发现 XFire 框架最大化的发挥了 POJO 的作用,减少了 SOA 实施时对框架本身的依赖,降低了 SOA 实施的难度,企业实施 SOA 时并不需要增加太多的投入就可以实现目标。

    最后附上工程源码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java调用net开发的webservice实例下载 问题终于解决了,之前加上?wsdl的时候报如下错: - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect - Retrying request - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect - Retrying request - I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect - Retrying request - java.net.ConnectException: Connection timed out: connect org.codehaus.xfire.fault.XFireFault: Couldn't send message. at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89) at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:30) at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131) at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79) at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114) at org.codehaus.xfire.client.Client.invoke(Client.java:336) at org.codehaus.xfire.client.Client.invoke(Client.java:368) at cn.watersoft.reportinfo.test.test.main(test.java:22) Caused by: org.codehaus.xfire.XFireException: Couldn't send message. at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:145) at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48) at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26) ... 6 more Caused by: java.net.ConnectException: Connection timed out: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:519) at java.net.Socket.connect(Socket.java:469) at java.net.Socket.(Socket.java:366) at java.net.Socket.(Socket.java:240) at org.apach

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值