在Java中编译基本网络服务客户端时出现错误。

huangapple go评论73阅读模式
英文:

Error when compiling a basic web service client in Java

问题

我尝试运行以下 Java EE Web 服务客户端已经好几天了

    package servclient;
    
    import tuto.helloserv.HelloService;
    import javax.xml.ws.WebServiceRef;
    
    public class ServClient {
    
        @WebServiceRef(wsdlLocation = "http://localhost:1991/HelloService/HelloService?wsdl")
        public static HelloService helloServ;
    
        public static void main(String[] args) {
            System.out.println(webCall("world"));
        }
    
        private static String webCall(java.lang.String arg0) {
            tuto.helloserv.Hello port = helloServ.getHelloPort();
            return port.webCall(arg0);
        }
    }

然而尽管 Web 服务的 URL 正确但我在 NetBeans 中遇到以下错误

    Exception in thread "main" java.lang.NullPointerException
    	at servclient.ServClient.webCall(ServClient.java:25)
    	at servclient.ServClient.main(ServClient.java:21)
    C:\Users\DevShop\Documents\wapps\ServClient\nbproject\build-impl.xml:1329: 执行此行时发生以下错误
    C:\Users\DevShop\Documents\wapps\ServClient\nbproject\build-impl.xml:981: Java 返回1
    BUILD FAILED总时间1 秒

我在我的机器上运行 Java 1.8.0_261但在任何已知论坛中都找不到明确的解决方案
英文:

I am trying to run the following java EE web service client for days:

package servclient;

import tuto.helloserv.HelloService;
import javax.xml.ws.WebServiceRef;

public class ServClient {

    @WebServiceRef(wsdlLocation = "http://localhost:1991/HelloService/HelloService?wsdl")
    public static HelloService helloServ;

    public static void main(String[] args) {
        System.out.println(webCall("world"));
    }

    private static String webCall(java.lang.String arg0) {
        tuto.helloserv.Hello port = helloServ.getHelloPort();
        return port.webCall(arg0);
    }
}

Yet I get the following error on netbeans even though the web service url is true;

Exception in thread "main" java.lang.NullPointerException
	at servclient.ServClient.webCall(ServClient.java:25)
	at servclient.ServClient.main(ServClient.java:21)
C:\Users\DevShop\Documents\wapps\ServClient\nbproject\build-impl.xml:1329: The following error occurred while executing this line:
C:\Users\DevShop\Documents\wapps\ServClient\nbproject\build-impl.xml:981: Java returned: 1
BUILD FAILED (total time: 1 second)

I run java 1.8.0_261 on my machine and I cant find any clear solution to this in any of the known forums.

答案1

得分: 1

The annotation @WebServiceRef is used with Java EE, not SE.

So in order to use the service from Java SE, you need to generate the client for the service from the WSDL.

See this tutorial about wsimport: Java Brains wsimport tool.
And this one too will help: Calling the service from generated client.

英文:

The annotation @WebServiceRef is used with java EE not SE

So in order to use the service from java SE you need to generate the client for the service from the wsdl

see this tutorial about wsimport : Java Brains wsimport tool
And this one too will help : Calling the service from generated client

huangapple
  • 本文由 发表于 2020年8月15日 00:24:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63416556.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定