繁体   English   中英

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

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

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

当我在本地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

我进行了搜索,找不到任何可以解释我的方案中的错误的信息。 我不确定从哪开始。 谁能阐明任何想法?

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

更新 :根据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);

谢谢,

保罗

据我所知,JAX-WS / CXF始终需要WSDL。 难道是您的WSDL包含在本地计算机上但不在Linux机器上的类路径中?

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

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

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

事实证明,面对相同的问题,我错过了以下缺点:

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

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

也许您已经在Windows下将它们放在类路径中了?

暂无
暂无

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

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