开发者社区> 问答> 正文

刚接触CXF,自己写的服务端和客户端例子,正常发布,客户端访问异常,求解答?报错

 

这样的 我在myEclipse中建了两个工程 一个普通的java工程 一个是web工程,部署在tomcat中, java工程里面一个接口,一个实现类,一个发布类,代码如下

IHelloWorld接口

package server; 

import javax.jws.WebParam; 

import javax.jws.WebService; 

@WebService  

public interface IHelloWorld { 

    //加入WebParam注解,以保证xml文件中参数名字的正确性  

    String sayHi(@WebParam(name="text") String text); 

}

HelloWorldImpl 实现类

package serverImpl; 

import javax.jws.WebService; 

import server.IHelloWorld;

@WebService (endpointInterface = "server.IHelloWorld", serviceName = "HelloWorld"

public class HelloWorldImpl implements IHelloWorld { 

    public String sayHi(String text) { 

        System.out.println("sayHi called"); 

        return "Hello " + text; 

    } 

}

serviceTest发布类

package run;

import javax.xml.ws.Endpoint; 

import serverImpl.HelloWorldImpl;

 

public class ServiceTest { 

 

    protected ServiceTest() throws Exception { 

        // START SNIPPET: publish  

        System.out.println("Starting Server"); 

        HelloWorldImpl implementor = new HelloWorldImpl(); 

        String address = "http://localhost:9000/helloWorld";

        Endpoint.publish(address, implementor); 

        // END SNIPPET: publish  

    } 

    public static void main(String args[]) throws Exception { 

        new ServiceTest(); 

        System.out.println("Server ready..."); 

        Thread.sleep(5 * 60 * 1000); 

        System.out.println("Server exiting"); 

        System.exit(0); 

    } 

在新建的web工程里面,把java工程中的IHelloWorld接口连包一起考过去,然后在index.jsp中写上一段java代码 如下:

    ClientProxyFactoryBean factory = new ClientProxyFactoryBean();

    factory.setAddress("http://localhost:9000/helloWorld");

    factory.getServiceFactory().setDataBinding(new AegisDatabinding());

    IHelloWorld ser=factory.create(IHelloWorld.class);

    ser.sayHi("hello~~-v-");

运行发布类 java工程中的ServicTest(发布5分钟),然后运行tomcat访问web工程中的index.jsp页面,报错如下~~自己找了好久也没找到解决办法,请问大家能够告诉我哪里做错了么?

Interceptor for {http://serverImpl/}HelloWorld#{http://server/}sayHi has thrown exception, unwinding now

org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"http://server/", local:"arg0")。所需元素为<{}text>

展开
收起
爱吃鱼的程序员 2020-06-22 20:59:57 551 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    这客服端默认生成的请求参数是arg0,不是text,你用spoaui看下就知道了

    2020-06-22 21:00:15
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《基于 Service Worker 实现在线代理》 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载