java Webservice 客户端找不到 wsdl
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12009892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Webservice client cannot find wsdl
提问by user973718
I have created two webservices clients in NetBeans 7.1, mimicking the tutorial they have on their website.
我已经在 NetBeans 7.1 中创建了两个 Web 服务客户端,模仿他们网站上的教程。
I had done the first one a while ago against a wsdl file located at a http location, and had no problem using the webservice
不久前,我针对位于 http 位置的 wsdl 文件完成了第一个操作,并且使用 webservice 没有问题
The webservice I am working with at the moment has a wsdl file located at a https location. The setup of the service went off without a hitch. The only difference with the first one was a popup alerting me to a security certificate, which I accepted. Service, Generated Sources, META-INF etc are all created successfully. A local copy of the wsdl file is stored on my pc under the src/.. folder.
我目前使用的网络服务有一个位于 https 位置的 wsdl 文件。服务的设置顺利进行。与第一个的唯一区别是一个弹出窗口,提醒我安全证书,我接受了。服务、生成源、META-INF 等都创建成功。wsdl 文件的本地副本存储在我的电脑上的 src/.. 文件夹下。
However, as soon as I go to run my code, I receive this error:
但是,一旦我开始运行我的代码,就会收到此错误:
Cannot find 'https://-domain-.net/-XYZServices-/-ABCXML?wsdl-'wsdl. Place the resource correctly in the classpath.
找不到“ https://-domain-.net/-XYZServices-/-ABCXML?wsdl-”wsdl。将资源正确放置在类路径中。
I found several similar issues in Stackoverflow and other places online, but nothing that really addressed my problem. I tried several suggestions anyway:
我在 Stackoverflow 和网上的其他地方发现了几个类似的问题,但没有真正解决我的问题。无论如何,我尝试了几个建议:
I checked the jax-ws-catalog.xml file, and found the url quoted above mapped to the local folder where the local copy of the wsdl is stored. I checked whether that local folder actually contained the wsdl file - it did. I tried editing the url in the jax-ws-catalog.xml file to point to port 8080 and 8081 - no joy.
我查看了 jax-ws-catalog.xml 文件,发现上面引用的 url 映射到了存储 wsdl 本地副本的本地文件夹。我检查了该本地文件夹是否确实包含 wsdl 文件 - 确实如此。我尝试编辑 jax-ws-catalog.xml 文件中的 url 以指向端口 8080 和 8081 - 不高兴。
I guess it is a security issue, but have no clue as to how to fix this.
我想这是一个安全问题,但不知道如何解决这个问题。
Can anyone point me in the right direction here.
任何人都可以在这里指出我正确的方向。
FYI: I'm fairly new to java and NetBeans.
仅供参考:我对 Java 和 NetBeans 还很陌生。
Thanks.
谢谢。
回答by damodar
The best way to avoid the error "Cannot find wsdl. Place the resource correctly in the classpath." is to use wsdllocation to specify the location of the wsdl and also to package the wsdl as part of the jar.
避免错误“找不到 wsdl。将资源正确放置在类路径中”的最佳方法。是使用 wsdllocation 指定 wsdl 的位置,并将 wsdl 打包为 jar 的一部分。
When you specify the wsdllocation make sure you add "/" to the beginning of the location.
当您指定 wsdllocation 时,请确保将“/”添加到位置的开头。
wsimport -keep -Xnocompile -wsdllocation /schema/10.0/MyService.wsdl schema/10.0/MyService.wsdl
回答by Mike
Not sure if this helps, but...
不确定这是否有帮助,但是...
From Here
从这里
On the client side to consume SSL enabled Web service: - in the New Web Service Client wizard under WSDL and Client location specify the WSDL file of the Web Service by setting WSDL URL in form of https://:8181// - then right click on the created web service and choose Edit Web Service Attributes and under Wsimport Options correct the wsdlLocation option to the following form: /META-INF/wsdl/_8181//.wsdl
Whenever you refresh the web service a fresh wsdl file gets loaded from the deployed application and the wsdl file gets loaded as a resource defined by the correct path (mentioned wsdlLocation option value).
在客户端使用启用 SSL 的 Web 服务: - 在 WSDL 和客户端位置下的新建 Web 服务客户端向导中,通过以 https://:8181// 的形式设置 WSDL URL 来指定 Web 服务的 WSDL 文件 - 然后向右单击创建的 Web 服务并选择 Edit Web Service Attributes,然后在 Wsimport Options 下将 wsdlLocation 选项更正为以下形式:/META-INF/wsdl/_8181//.wsdl
每当您刷新 Web 服务时,都会从部署的应用程序加载一个新的 wsdl 文件,并且该 wsdl 文件将作为由正确路径(提到的 wsdlLocation 选项值)定义的资源加载。
回答by zygimantus
Just put your WSDL file in your classpath, etc., src/main/resources/MyWsdl.xml and use this to get it:
只需将您的 WSDL 文件放在您的类路径等中,src/main/resources/MyWsdl.xml 并使用它来获取它:
URL url = new URL(baseUrl, "classpath:MyWsdl.xml");
Also do not forget to add this on your service class that extends javax.xml.ws.Service:
也不要忘记在扩展 javax.xml.ws.Service 的服务类中添加它:
@WebServiceClient(name = "MyService", targetNamespace = "http://example.org/", wsdlLocation = "classpath:MyWsdl.xml")
回答by skywards
Make sure that you have configured your web service.
One way to do so is to implement a class that extends javax.ws.rs.core.Application
. That is, add a class which is similar to the following:
确保您已配置 Web 服务。一种方法是实现一个扩展javax.ws.rs.core.Application
. 即,添加一个类似于以下内容的类:
import java.util.Set;
import javax.ws.rs.core.Application;
@javax.ws.rs.ApplicationPath("rest")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
addRestResourceClasses(resources);
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(rest.HelloWorld.class);
resources.add(rest.Search.class);
// Here continue adding all the JAX-RS classes that you have
}
}