当前位置: 代码迷 >> Java相关 >> 急求 java中webService解决方案
  详细解决方案

急求 java中webService解决方案

热度:6170   发布时间:2013-02-25 21:45:41.0
急求 java中webService
我是建立了一个 web Service项目 helloService jax-ws







Customer 
package net.ilkj.soap.server;

import java.util.Date;

import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Customer")
public class Customer {
private long id;
private String name;
private Date birthday;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}





package net.ilkj.soap.server;

import javax.jws.WebService;
@WebService
public interface IHelloService {
Customer selectMaxAgeStudent(Customer c1, Customer c2);
Customer selectMaxLongNameStudent(Customer c1, Customer c2);
}





package net.ilkj.soap.server;

public class HelloServiceImpl implements IHelloService {

@Override
public Customer selectMaxAgeStudent(Customer c1, Customer c2) {
if (c1.getBirthday().getTime() > c2.getBirthday().getTime())
return c2;
else
return c1;
}
@Override
public Customer selectMaxLongNameStudent(Customer c1, Customer c2){
if (c1.getName().length() > c2.getName().length())
return c1;
else
return c2;
}
}




package net.ilkj.soap.server;

import javax.xml.ws.Endpoint;
public class SoapServer {
public static void main(String[] args) {
Endpoint.publish("http://127.0.0.1:8080/helloService",new HelloServiceImpl());
}
}



运行SoapServer 时  


Exception in thread "main" java.lang.NullPointerException
at com.sun.xml.internal.ws.server.EndpointFactory.getWsdlLocation(EndpointFactory.java:385)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.getPrimaryWsdl(EndpointImpl.java:265)
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 net.ilkj.soap.server.SoapServer.main(SoapServer.java:6)


那里出错了  



------解决方案--------------------------------------------------------
你是乍运行的。。。。

webservice要利用服务器发布一个地址才可以,服务器呢???
------解决方案--------------------------------------------------------
访问可以通过代理或者远程地址才可以访问吧?楼主用框架没?
------解决方案--------------------------------------------------------
jax-ws做webservice比较麻烦 本人觉得CXF比较简单 还有AXIS也可以
  相关解决方案