【问题标题】:Importing a WebService:导入 Web 服务:
【发布时间】:2010-03-19 16:53:15
【问题描述】:

我正在尝试导入以下网络服务:http://www.biomart.org/biomart/martwsdl

对服务 getResistry() 使用 curl :一切正常:

curl --header 'Content-Type: text/xml' --data '<?xml version="1.0"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mar="http://www.biomart.org:80/MartServiceSoap">
<soapenv:Header/>
   <soapenv:Body>
      <mar:getRegistry/>
   </soapenv:Body>
</soapenv:Envelope>' http://www.biomart.org:80/biomart/martsoap

它返回:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.o
rg/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/
envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <soap:Body>
    <getRegistryResponse xmlns="http://www.biomart.org:80/MartServiceSoap">
      <mart>
        <name xsi:type="xsd:string">ensembl</name>
        <displayName xsi:type="xsd:string">ENSEMBL GENES 57 (SANGER UK)</displayName>
        <database xsi:type="xsd:string">ensembl_mart_57</database>
(...)

好的。

但是当使用CXF/wsdl2java(甚至是wsimport)生成这个服务时

mkdir src
wsdl2java -keep -d src -client "http://www.biomart.org/biomart/martwsdl"
javac -g -d src -sourcepath src src/org/biomart/_80/martservicesoap/MartServiceSoap_BioMartSoapPort_Client.java
java -cp src org.biomart._80.martservicesoap.MartServiceSoap_BioMartSoapPort_Client

生成的客户端为 getRegistry() 返回一个 empty 列表:

Invoking getRegistry...
getRegistry.result=[]

为什么?我应该怎么做才能使这段代码正常工作?

非常感谢

皮埃尔

【问题讨论】:

  • 请出示MartServiceSoap_BioMartSoapPort_Client.java中的代码,特别是main方法,后面跟调用服务的地方。
  • @shivaspk MartServiceSoap_BioMartSoapPort_Client.java 由 CXF/wsdl2java 使用“-client”选项生成。
  • 它只生成一个存根类,它所做的只是创建 WSDL 操作的 java 等价物,您需要编写一个简单的 java 程序来调用 getRegitry() 操作。

标签: java web-services wsdl cxf wsdl2java


【解决方案1】:

在客户端类中有一个 main 方法,您可以在其中调用 getRegistry 操作。

它可能看起来像这样

MartServiceSoap_BioMartSoapPort_Client client = new MartServiceSoap_BioMartSoapPort_Client();
System.out.println(client.getRegistry());

【讨论】:

  • 对不起,忘了提,然后使用 javac 和 java 编译和运行这个客户端类。
  • 抱歉,由 CXF/wsdl2java 生成的客户端确实生成了一个 main 方法,并且代码包含对 getRegistry() 的调用。 java.util.List<org.biomart._80.martservicesoap.Mart> _getRegistry__return = port.getRegistry(); System.out.println("getRegistry.result=" + _getRegistry__return);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-16
  • 2012-05-09
  • 2023-03-14
  • 1970-01-01
相关资源
最近更新 更多