简体   繁体   English

Webservice客户端找不到wsdl

[英]Webservice client cannot find wsdl

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 文件完成了第一个,并且使用 web 服务没有问题

The webservice I am working with at the moment has a wsdl file located at a https location.我目前正在使用的网络服务有一个位于 https 位置的 wsdl 文件。 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. Service、Generated Sources、META-INF 等都创建成功。 A local copy of the wsdl file is stored on my pc under the src/.. folder. 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.找不到“ https://-domain-.net/-XYZServices-/-ABCXML?wsdl-”wsdl Place the resource correctly in the classpath.将资源正确放置在类路径中。

I found several similar issues in Stackoverflow and other places online, but nothing that really addressed my problem.我在 Stackoverflow 和其他在线地方发现了几个类似的问题,但没有真正解决我的问题。 I tried several suggestions anyway:无论如何,我尝试了几个建议:

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.我检查了 jax-ws-catalog.xml 文件,发现上面引用的 url 映射到存储 wsdl 本地副本的本地文件夹。 I checked whether that local folder actually contained the wsdl file - it did.我检查了该本地文件夹是否实际上包含 wsdl 文件 - 它确实包含。 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 以指向端口 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.谢谢。

The best way to avoid the error "Cannot find wsdl. Place the resource correctly in the classpath."避免错误“找不到 wsdl。将资源正确放置在类路径中”的最佳方法。 is to use wsdllocation to specify the location of the wsdl and also to package the wsdl as part of the jar.就是使用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

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在客户端使用启用 SSL 的 Web 服务: - 在 WSDL 和客户端位置下的新建 Web 服务客户端向导中,通过以 https://:8181// 的形式设置 WSDL URL 来指定 Web 服务的 WSDL 文件 - 然后对单击创建的 Web 服务并选择编辑 Web 服务属性并在 Wsimport 选项下将 wsdlLocation 选项更正为以下形式:/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).每当您刷新 Web 服务时,都会从已部署的应用程序加载新的 wsdl 文件,并且 wsdl 文件会作为由正确路径定义的资源(提到的 wsdlLocation 选项值)加载。

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")

Make sure that you have configured your web service.确保您已配置 Web 服务。 One way to do so is to implement a class that extends javax.ws.rs.core.Application .一种方法是实现一个扩展javax.ws.rs.core.Application的类。 That is, add a class which is similar to the following:也就是说,添加一个类似于以下的类:

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
    }

}

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

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