码迷,mamicode.com
首页 > 其他好文 > 详细

XFire客户端调用CXF服务端(四)

时间:2018-01-09 12:53:57      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:serve   auth   void   ati   code   space   参数   ram   ring   

前面章节:http://www.cnblogs.com/xiehongwei/p/8082337.html 已经开发出了CXF服务端,现在用XFire开发客户端调用CXF服务端,代码如下:

import java.net.MalformedURLException;
import java.net.URL;

import org.codehaus.xfire.client.Client;

/**
 * @filename XfireClient.java
 * @author xiehongwei
 * @date 2018-1-9 上午10:55:39
 *
 */
public class XfireClient {

    public static void main(String[] args) throws MalformedURLException, Exception {
        Client client = new Client(new URL("http://localhost:8082/CxfWSServer/webservice/helloWorld?wsdl"));
        Object[] results = client.invoke("sayHi", new Object[] { " World" });
        System.out.println(results[0]);
    }
    
}

注意:我本地跑了多个tomcat,暂时改了下端口(不影响)

但是运行发现报错,错误如下:

Retrieving document at ‘http://localhost:8082/CxfWSServer/webservice/helloWorld?wsdl=HelloWorld.wsdl‘.
Exception in thread "main" org.codehaus.xfire.fault.XFireFault: Unmarshalling Error: unexpected element (uri:"http://impl.ws.xie.com/", local:"arg0"). Expected elements are <{}arg0> 
    at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
    at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
    at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
    at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Client.onReceive(Client.java:382)
    at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
    at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
    at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:75)
    at org.codehaus.xfire.client.Client.invoke(Client.java:335)
    at org.codehaus.xfire.client.Client.invoke(Client.java:349)
    at com.test.XfireClient.main(XfireClient.java:18)

通过网上知识搜索发现需要在接口参数上加@WebParam 写入命名空间,接口修改如下:

package com.xie.ws;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface HelloWorld {

//    String sayHi(String username); 
    String sayHi(@WebParam(targetNamespace= "http://com.xie.ws/")String username); 
}

注意:红色部分为接口所在报名路径

再重新测试成功。

 

XFire客户端调用CXF服务端(四)

标签:serve   auth   void   ati   code   space   参数   ram   ring   

原文地址:https://www.cnblogs.com/xiehongwei/p/8250792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!