简体   繁体   English

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

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

I have used CXF's wsdl2java to generate code from a WSDL file. 我已经使用CXF的wsdl2java从WSDL文件生成代码。 I then build the code using the ant build xml file (also generated by CXF's wsdl2java). 然后,我使用ant build xml文件(也由CXF的wsdl2java生成)来构建代码。

When I run my code on my local Java 7 machine, all is well. 当我在本地Java 7计算机上运行代码时,一切都很好。 When I run the code on a linux box in the cloud running Java 1.5, I get the following error: 在运行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 保罗

To my knowledge, JAX-WS/CXF always requires the WSDL. 据我所知,JAX-WS / CXF始终需要WSDL。 Could it be that you have the WSDL included on the classpath somewhere on your local machine but not on your linux box? 难道是您的WSDL包含在本地计算机上但不在Linux机器上的类路径中?

Regardless, you should be able to fix this issue by using the Service.create(URL, QNAME) method. 无论如何,您都应该能够通过使用Service.create(URL, QNAME)方法来解决此问题。 The URL needs to point to the WSDL, you can use either the web service endpoint + ?wsdl on the end, or save a copy of the WSDL locally and point to that instead. URL需要指向WSDL,您可以在最后使用Web服务端点+ ?wsdl ,或在本地保存WSDL的副本并指向它。

In your comment you mention referencing the WSDL on the web being preferable. 在您的评论中,您提到最好引用Web上的WSDL。 Personally I would store it locally as this will improve performance when calling the web service. 我个人将其存储在本地,因为这将在调用Web服务时提高性能。 The framework won't need to make a call over the network just to get the WSDL every time you create the proxy. 每次创建代理时,该框架都不需要通过网络进行调用即可获取WSDL。

This happens if he web service uses authentication. 如果他的Web服务使用身份验证,则会发生这种情况。 The WSDL cannot be read until the user name and password have been entered... 在输入用户名和密码之前,无法读取WSDL。

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下将它们放在类路径中了?

暂无
暂无

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

相关问题 调用 WSDL 服务时出现 javax.xml.ws.WebServiceException - javax.xml.ws.WebServiceException when invoking WSDL service javax.xml.ws.WebServiceException: 无法访问 WSDL - javax.xml.ws.WebServiceException: Failed to access the WSDL javax.xml.ws.WebServiceException:找不到以wsdl命名的服务 - javax.xml.ws.WebServiceException: Could not find service named in wsdl javax.xml.ws.WebServiceException:org.apache.cxf.service.factory.ServiceConstructionException:创建服务失败 - javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service “ javax.xml.ws.WebServiceException:不是有效的服务。”代理问题? - “javax.xml.ws.WebServiceException: is not a valid service.” proxy issue? 无法创建服务异常javax.xml.ws.WebServiceException: - Failed to create service exception javax.xml.ws.WebServiceException: 在 java 中导入 javax.xml.ws.WebServiceException 时出错 class - Error while importing javax.xml.ws.WebServiceException in java class javax.xml.ws.WebServiceException:不是有效的端口 - javax.xml.ws.WebServiceException: is not a valid port Weblogic 12.2-CXF 3.1-JAXB 2.2-部署:错误javax.xml.ws.WebServiceException:java.lang.IllegalStateException:未绑定前缀X - Weblogic 12.2 - CXF 3.1 - JAXB 2.2 - Deployment : Error javax.xml.ws.WebServiceException: java.lang.IllegalStateException: The prefix X is not bound javax.xml.ws.WebServiceException:方法X暴露为WebMethod,但是没有对应的wsdl操作 - javax.xml.ws.WebServiceException: Method X is exposed as WebMethod, but there is no corresponding wsdl operation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM