英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论