简体   繁体   English

无法从Groovy调用Web服务

[英]Unable to call a web service from Groovy

I'm going through the first examples from the new Java Web Services: Up and Running book. 我正在研究新Java Web Services:启动和运行中的第一个示例。 I tried to go through the SOAP client example for Java on page 13, but in Groovy. 我尝试在第13页上(但在Groovy中)浏览Java的SOAP客户端示例。

So here is my Groovy shell code: 所以这是我的Groovy shell代码:

import javax.xml.namespace.QName
import javax.xml.ws.Service
import java.net.URL

url = new URL("http://someURL?wsdl")
qname = new QName("http://someURL", "SomeURLImplService")
service = Service.create(url, qname)

But this fails with this error: 但这失败,并显示以下错误:

ERROR groovy.lang.MissingMethodException: No signature of method: \
static javax.xml.ws.Service.create() is applicable for argument types: \
(java.net.URL, javax.xml.namespace.QName) values: {http://someURL?wsdl, \
{http://someURL}SomeURLImplService}

I do not understand this, since Groovy tells me this method with that signature does indeed exist: 我不明白这一点,因为Groovy告诉我这种带有该签名的方法确实存在:

groovy:000> Service.class.getMethods().each {println it}
public static javax.xml.ws.Service \
javax.xml.ws.Service.create(java.net.URL,javax.xml.namespace.QName)
...

Does anybody know what I am doing wrong here? 有人知道我在这里做错了吗?

I tried to run your code with no modifications and it worked fine for me. 我试图在不做任何修改的情况下运行您的代码,它对我来说效果很好。 Your issue might be related to the Java version or the classpath. 您的问题可能与Java版本或类路径有关。 The javax.xml.ws (JAX-WS) is only part of the Java SE starting with Java 6. If you are not running this test in Java 6, that might be your problem. 从Java 6开始,javax.xml.ws(JAX-WS)只是Java SE的一部分。如果您不在Java 6中运行此测试,则可能是您的问题。 That is probably not your issue since if you were not, I would not expect you to be able to resolve those interfaces. 这可能不是您的问题,因为如果没有,我不希望您能够解决这些接口。

The other thing it might be is a classpath issue. 另一件事可能是类路径问题。 External JAX-WS providers can be plugged into the Java runtime. 可以将外部JAX-WS提供程序插入Java运行时。 Do you have anything on your classpath that is the JAX-WS provider? 您的类路径上是否有JAX-WS提供程序的任何内容? Perhaps it is an earlier version. 也许是早期版本。

I tried again by downloading Groovy manually (instead of using the distribution that came with Ubuntu). 我再次尝试通过手动下载Groovy(而不是使用Ubuntu随附的发行版)进行尝试。 Now it works. 现在可以了。 Go figure. 去搞清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM