首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web开发 >

web service初学遇到的有关问题

2012-12-14 
web service初学遇到的问题package org.zttc.serviceimport javax.xml.ws.Endpointpublic class MyServe

web service初学遇到的问题
package org.zttc.service;

import javax.xml.ws.Endpoint;

public class MyServer {

public static void main(String[] args) {
String address = "http://localhost:8888/ns";
Endpoint.publish(address, new MyServiceImpl());
}

}
////////////////////主类
package org.zttc.service;

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

@WebService()
public interface IMyService {

@WebResult(name="addResult")
public int add(@WebParam(name="a")int a,@WebParam(name="b")int b);

@WebResult(name="minusResult")
public int minus(@WebParam(name="a")int a,@WebParam(name="b")int b);

@WebResult(name="loginUser")
public User login(@WebParam(name="username")String username,@WebParam(name="password")String password);

}
//////////////////////////////////////接口
package org.zttc.service;

import javax.jws.WebService;

@WebService(endpointInterface="org.zttc.service.IMyService")
public class MyServiceImpl implements IMyService {

@Override
public int add(int a, int b) {
System.out.println(a+"+"+b+"="+(a+b));
return a+b;
}

@Override
public int minus(int a, int b) {
System.out.println(a+"-"+b+"="+(a-b));
return a-b;
}

@Override
public User login(String username, String password) {
System.out.println(username+" is logining");
User user = new User();
user.setId(1);
user.setUsername(username);
user.setPassword(password);
return user;
}

}
////////////////////////////////////////////用户端
Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class org.zttc.service.jaxws.Add is not found. Have you run APT to generate them?
at com.sun.xml.internal.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:256)
at com.sun.xml.internal.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:567)
at com.sun.xml.internal.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:514)
at com.sun.xml.internal.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:341)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:227)
at com.sun.xml.internal.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:308)
at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:174)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:420)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:439)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:208)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:138)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:92)
at javax.xml.ws.Endpoint.publish(Endpoint.java:170)
at org.zttc.service.MyServer.main(MyServer.java:9)
///////////////////////////////////////////////////服务器报错
这是怎么一回事?求教。
[解决办法]
原因:cxf需要jaxws-api-2.1.jar及jaxb-api-2.1.jar的支持

解决方案 
1、将cxf所需的2.1的jar复制一份到jdk目录下的jre\lib\endorsed文件夹中。如果endorsed文件不存在,可新建。如果不行,可能还需要在public class XXX上方加入@SOAPBinding(style = SOAPBinding.Style.RPC)。


2、jdk升级到1.6.0_22版本以上。

热点排行