java 获取 CXF 错误:javax.xml.ws.WebServiceException:WSDL 元数据不可用于创建代理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17839949/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 15:11:04  来源:igfitidea点击:

Getting CXF error: javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy

javaweb-servicessoapwsdlcxf

提问by user265330

I have used CXF's wsdl2java to generate code from a WSDL file. I then build the code using the ant build xml file (also generated by CXF's wsdl2java).

我使用 CXF 的 wsdl2java 从 WSDL 文件生成代码。然后我使用 ant build xml 文件(也由 CXF 的 wsdl2java 生成)构建代码。

When I run my code on my local Java 7 machine, all is well. When I run the code on a linux box in the cloud running Java 1.5, I get the following error:

当我在本地 Java 7 机器上运行我的代码时,一切都很好。当我在运行 Java 1.5 的云中的 linux 机器上运行代码时,出现以下错误:

javax.xml.ws.WebServiceException: WSDL Metadata not available to create the proxy,
either Service instance or ServiceEndpointInterface com.a.b.TheService should have
WSDL information

I've had a search around and I can't find any information that might explain the error in my scenario. I'm not sure where to start on this one. Can anyone shed any light?

我四处搜索,但找不到任何可以解释我的场景中的错误的信息。我不知道从哪里开始这个。任何人都可以发光吗?

I mentioned Java versions above as it is an obvious difference, but it may have nothing to do with the problem.

我在上面提到了Java版本,因为它是一个明显的区别,但它可能与问题无关。

UPDATE: Adding in the code below as a result of Syon's request:

更新:根据 Syon 的要求添加以下代码:

private static final String servicesNamespace = "http://www.serviceprovider.com/services/2009/03/02";
private static final String servicesNamespaceSchema = "http://www.serviceprovider.com/services/2009/03/02/schema";
private static String SERVICE_NAME = "TheService";
private QName SERVICE_QNAME;
private TheService m_theService;
...

SERVICE_QNAME = new QName(servicesNamespace, SERVICE_NAME);

I wrote this code quite some time ago, and at the time I wrote the comment below.
I've included it here in case it is helpful:

// The sample code creates an instance of the generated TheService_Service class.
// TheService_Service has references to the local WSDL file that it was generated from, and
// will report an error if it is not found. To prevent that error, we could:
// (1) ensure that the WSDL is available locally in the production environment in the location
//     referenced in the generated Java
// (2) generate the Java from the WSDL located on the web rather than local WSDL, meaning that
//     the WSDL referenced in the generated Java would be a URL to where it is located on
//     serviceproviders's web site.
// (3) Rather than create an instance of TheService_Service, just create an instance of its
//     super class, javax.xml.ws.Service, which has a static method to create an instance of it that
//     does not require the location of the WSDL to be passed to it.
// I am going to choose option (3). Option (2) is a close second.

Service service = Service.create(SERVICE_QNAME);
m_theService = service.getPort(TheService.class);   <-- Fails here

((BindingProvider)m_theService).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);

Binding binding = ((BindingProvider)m_theService).getBinding();
((SOAPBinding)binding).setMTOMEnabled(false);

Thanks,

谢谢,

Paul

保罗

回答by Syon

To my knowledge, JAX-WS/CXF always requires the WSDL. Could it be that you have the WSDL included on the classpath somewhere on your local machine but not on your linux box?

据我所知,JAX-WS/CXF 总是需要 WSDL。可能是您将 WSDL 包含在本地机器上的类路径中,但没有包含在您的 linux 机器上?

Regardless, you should be able to fix this issue by using the Service.create(URL, QNAME)method. The URL needs to point to the WSDL, you can use either the web service endpoint + ?wsdlon the end, or save a copy of the WSDL locally and point to that instead.

无论如何,您应该能够使用该Service.create(URL, QNAME)方法解决此问题。URL 需要指向 WSDL,您可以?wsdl在末尾使用 Web 服务端点 + ,或者在本地保存 WSDL 的副本并指向它。

In your comment you mention referencing the WSDL on the web being preferable. Personally I would store it locally as this will improve performance when calling the web service. The framework won't need to make a call over the network just to get the WSDL every time you create the proxy.

在您的评论中,您提到在网络上引用 WSDL 是可取的。我个人会将它存储在本地,因为这将提高调用 Web 服务时的性能。每次创建代理时,该框架都不需要通过网络进行调用来获取 WSDL。

回答by JRA_TLL

Faced with the same problem, it turned out, I was missing these depedencies:

面对同样的问题,事实证明,我错过了这些依赖:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.0.0</version>
    </dependency>

Just adding them to my classpath solved the problem.

只需将它们添加到我的类路径即可解决问题。

Maybe you had them already in the classpath under Windows?

也许你已经在 Windows 下的类路径中拥有它们?

回答by 0xc000005

This happens if he web service uses authentication. The WSDL cannot be read until the user name and password have been entered...

如果 Web 服务使用身份验证,就会发生这种情况。在输入用户名和密码之前无法读取 WSDL...