2

我使用 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);

谢谢,

保罗

4

3 回答 3

1

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

于 2014-10-24T14:51:03.083 回答
1

据我所知,JAX-WS/CXF 总是需要 WSDL。会不会是您在本地机器的某个地方的类路径中包含了 WSDL,但在您的 linux 机器上却没有?

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

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

于 2013-07-24T19:03:52.313 回答
1

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

    <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 下的类路径中?

于 2017-04-13T07:00:42.977 回答