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