Web服务 – JAVA JAX-WS NullPointerException在javax.xml.ws.Service.getPort(Service.java:188)

前端之家收集整理的这篇文章主要介绍了Web服务 – JAVA JAX-WS NullPointerException在javax.xml.ws.Service.getPort(Service.java:188)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在ubuntu下部署在jboss上的简单的“HelloWorld”Web服务.
我创建了简单的客户端,但我无法让它工作.我每次运行客户端时都会得到NullPointerException.

请注意,我正在Ubuntu下运行Oracle Java 7.

这是代码
HelloWorldClient.java

  1. import java.net.MalformedURLException;
  2. import java.net.URL;
  3.  
  4. import javax.xml.namespace.QName;
  5. import javax.xml.ws.Service;
  6.  
  7.  
  8. public class HelloWorldClient {
  9.  
  10. public static void main(String[] args){
  11. URL url;
  12. try {
  13. url = new URL("http://localhost:8080/WebServiceProject/helloWorld?wsdl");
  14. QName qname = new QName("http:///","HelloWorldImplService");
  15.  
  16. Service service = Service.create(url,qname);
  17.  
  18. HelloWorld hello = service.getPort(HelloWorld.class);
  19.  
  20. System.out.println(hello.sayHello("mkyong"));
  21. } catch (MalformedURLException e) {
  22. // TODO Auto-generated catch block
  23. e.printStackTrace();
  24. }
  25.  
  26. }

}

HelloWorld.java

  1. import javax.jws.WebMethod;
  2. import javax.jws.WebService;
  3.  
  4.  
  5. @WebService
  6. public interface HelloWorld {
  7.  
  8. @WebMethod
  9. public String sayHello(String name);
  10.  
  11. }

堆栈跟踪:

  1. Exception in thread "main" java.lang.NullPointerException
  2. at com.sun.xml.internal.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1407)
  3. at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:334)
  4. at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:354)
  5. at javax.xml.ws.Service.getPort(Service.java:188)
  6. at HelloWorldClient.main(HelloWorldClient.java:18)

在这一行抛出异常:

  1. HelloWorld hello = service.getPort(HelloWorld.class);

解决方法

我自己已经有同样的问题了几天,因为我使用的WSDL文件(和服务)被移动到一个新的URL.我终于在这里找到了解决方案:

http://techtracer.com/2007/08/15/jax-ws-jaxp-tutorial-building-a-stockquote-web-service-client/

总之,在使用以下命令(在Windows / CygWin上)重新生成所有自动生成的java和类文件之后,所有的东西(应该都有)开始工作了

  1. "C:/Program Files/Java/jdk1.8.0_31/bin/wsimport.exe" -keep https://domain.com/path_to_wsdl

我有一些额外的麻烦,因为一些旧的文件被遗留在与新生成文件冲突,但一切都慢慢开始工作后,我将所有的旧文件移动到回收站.

猜你在找的HTML相关文章