使用XFire调用WebService需注意的事项 (转载)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Inber/article/details/4149467

使用XFire调用WebService需注意的事项


2008-02-27 14:25:10
版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任。

 


(一):注意过滤输入和输出参数空白字符
如果出现空白字符解析不了导致调用失败,导致下面的异常:
org.codehaus.xfire.fault.XFireFault: Error writing document.. Nested exception is com.ctc.wstx.exc.WstxIOException: Invalid null character in text to output
at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:83)
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)

String.trim()一下即可。
 
(二):连接时注意修改一些参数
  比如:HttpClientParams.CONNECTION_MANAGER_TIMEOUT // 设置Timeout
  这其实不止是这里需要,任何网络编程都需要注意此事项。当对方服务死了或网络异常,
如果不做timeout处理,按照默认的时间去处理,将会导致服务积压严重甚至被脱死。
  HttpClientParams.USE_EXPECT_CONTINUE //client handshake
  如果服务不需要传输大量的数据,保持长连接,还是建议关闭掉此功能,设置为false。
否则,在业务量很大的情况下,很容易将服务端和自己都搞的很慢甚至拖死。
  HttpClientParams params = new HttpClientParams();
// 避免'Expect: 100-continue' handshake
params.setParameter(HttpClientParams.USE_EXPECT_CONTINUE,Boolean.FALSE);
//设置ws连接超时时间
params.setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 1000);
client.setProperty(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS,params);
展开阅读全文

XFire调用WebService异常

09-17

出现异常:rn[size=14px] org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Cannot open connection[/size]rnrn代码:rn[code=Java]rn//导入包的代码省略rnpublic class ConnectShincoNavigation rnrn public static String WebServiceURL = rn "http://192.168.0.11:8080/sanyECCwebservices/services/ServiceSocket";rn rn private Service srvcModel = null;rn rn private XFireProxyFactory factory = null;rn rn private ServiceSocketPortType srvc = null;rnrn public ConnectShincoNavigation()rn createObject();rn rnrn public void createObject()rn //创建服务对象rn srvcModel = new ObjectServiceFactory().create(ServiceSocketPortType.class);rn rn //使用XFire的服务工厂,生成创建实例rn factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());rn rn tryrn srvc = (ServiceSocketPortType)factory.create(rn srvcModel,WebServiceURL);rn catch(MalformedURLException e)rn System.out.println(e.toString());rn rn rnrn public void forwardOnlineStatus(String serviceId, boolean onlineStatus)rn tryrn String result = srvc.isOnline(serviceId, onlineStatus);rn System.out.println("调用WebService结果:" + result);rn catch(Exception e)rn System.out.println(e.toString());rn rn rnrn[/code]rnrn调用代码:rn[code=Java]rnConnectShincoNavigation csn = new ConnectShincoNavigation();rncsn.forwardOnlineStatus("10003",true);rn[/code]rnrn把WebService放在本机上,WebServiceURL改成"http://127.0.0.1:8080/sanyECCwebservices/services/ServiceSocket",程序调用不会报异常,WebService放在别人电脑上,我调用就会出现上面的异常,也换过除了XFire以外的方式调用,还是报Cannot open connection,不知道是什么原因?请大家指点一下 论坛

关于使用XFIRE调用webservice的问题

05-13

使用XFIRE生成的客户端调用.net的webservice,可以访问wsdl,但用客户端调用就报401错误:rn- 100 (continue) read timeout. Resume sending the requestrn- ntlm authentication scheme selectedrn- No credentials available for NTLM @user-37:80rn- Server returned error code = 401 for URI : http://user-37/SaaSWSInterface/SaaS2ISVInterface.asmx. Check server logs for detailsrnException in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Server returned error code = 401 for URI : http://user-37/SaaSWSInterface/SaaS2ISVInterface.asmx. Check server logs for detailsrnorg.codehaus.xfire.fault.XFireFault: Server returned error code = 401 for URI : http://user-37/SaaSWSInterface/SaaS2ISVInterface.asmx. Check server logs for detailsrn at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89)rn at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:83)rn at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)rn at org.codehaus.xfire.client.Client.invoke(Client.java:336)rn at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)rn at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)rn at $Proxy12.saaSISVInterface(Unknown Source)rn at test2.Client.main(Client.java:26)rnCaused by: org.codehaus.xfire.XFireRuntimeException: Server returned error code = 401 for URI : http://user-37/SaaSWSInterface/SaaS2ISVInterface.asmx. Check server logs for detailsrn at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:130)rn at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)rn at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)rn at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)rn at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)rn ... 6 morern请问应该怎么办 论坛

xfire 调用天气预报webservice exception 。。。。

06-16

天气预报webservice 地址rnhttp://webservice.webxml.com.cn/webservices/weatherws.asmxrn大家可以在地址栏看看这个地址rn我用xfire写了个简单的客户端调用 出现了异常:rn[code=Java]rnClient client=new Client(new URL("http://webservice.webxml.com.cn/webservices/weatherws.asmx?wsdl"));rnObject[] result=client.invoke("getWeather", new String[]"1662");rnfor (int i = 0; i < result.length; i++) rn System.out.println(result[i]);rnrn[/code]rnrn异常信息如下 rnrnorg.codehaus.xfire.fault.XFireFault: 服务器无法处理请求。 ---> 值不能为空。rn参数名: inputrn at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)rn at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)rn at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)rn at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)rn at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)rn at org.codehaus.xfire.client.Client.onReceive(Client.java:406)rn at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)rn at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)rn at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)rn at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)rn at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)rn at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)rn at org.codehaus.xfire.client.Client.invoke(Client.java:336)rn at org.codehaus.xfire.client.Client.invoke(Client.java:368)rn at com.web.service.TestClient.main(TestClient.java:38)rnrn大家帮我看看是怎么回事 感激不尽 rnrn 论坛

没有更多推荐了,返回首页