- PR -

メッセージング型のWSDLをwsdl2javaするとエラーとなります

1
投稿者投稿内容
entama
会議室デビュー日: 2005/11/26
投稿数: 2
投稿日時: 2005-11-26 22:12
初めて投稿します。
どなたか分かる方がいれば、ご教示をお願いします。

メッセージング型のサーバ側・WEBサービスプログラム(*1)を、java2wsdlしてWSDLを作成しました(*2)。このWSDLからクライアント側プログラムを作ろうとwsdl2javaしたところ次のようなエラーが出ました。
[axis-wsdl2java] java.io.IOException: Type SOAPConstants is referenced but not defined.

ネットでいろいろ検索したのですが、ヒントが見当たらず、対応方法がわからず困っています。どなたか分かる方がいれば教えて下さい。

環境は、winXP-SP2,AXIS1.1,eclipse2.1.3です。
wsdl2java実行時のクラスパスには以下を通してあります。
axis-ant.jar
axis.jar
commons-discovery.jar
commons-logging.jar
jaxrpc.jar
log4j-1.2.8.jar
saaj.jar
wsdl4j.jar

プログラム、WSDLともかなり行数があります。
一応、削らずに載せました...

(*1)サーバ側・WEBサービスプログラム
package jp.co.ndc.OrderService2;
import org.w3c.dom.*;
import org.apache.axis.message.SOAPBody;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.message.SOAPEnvelope;

public class OrderService2 {
public void getPriceInfo(SOAPEnvelope requestEnvelope,
SOAPEnvelope responseEnvelope) throws Exception {

SOAPBody requestBody = (SOAPBody)requestEnvelope.getBody();
Element bodyElem = requestBody.getAsDOM();
Element productElem = (Element)bodyElem.getElementsByTagNameNS( "urn:ProductData", "product").item(0);
Element nameElem = (Element)productElem.getElementsByTagNameNS(
"urn:ProductData", "name").item(0);

String name = nameElem.getFirstChild().getNodeValue();
Element quantityElem = (Element)productElem.getElementsByTagNameNS(
"urn:ProductData", "quantity").item(0);
String quantity = quantityElem.getFirstChild().getNodeValue();
String ret = (name.equals("pen") ? Integer.toString
     (100 * Integer.parseInt(quantity)) : "0");

Document doc = productElem.getOwnerDocument();
Element price = doc.createElementNS("urn:ProductData", "price");
Text textNode = doc.createTextNode( ret );
price.appendChild(textNode);
productElem.appendChild(price);

responseEnvelope.addBodyElement(new SOAPBodyElement(productElem));
}
}


(*2)WSDLです

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="OrderService2"
xmlns:impl="OrderService2" xmlns:intf="OrderService2"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns1="http://message.axis.apache.org"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">

<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://message.axis.apache.org">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="SAX2EventRecorder">
<sequence>
<element name="length" type="xsd:int"/>
</sequence>
</complexType>
<complexType name="MessageElement">
<sequence>
<element name="ID" nillable="true" type="xsd:string"/>
<element name="NSMappings" nillable="true" type="soapenc:Array"/>
<element name="QName" nillable="true" type="xsd:QName"/>
<element name="allAttributes" nillable="true" type="xsd:anyType"/>
<element name="asDOM" nillable="true" type="apachesoap:Element"/>
<element name="asDocument" nillable="true" type="apachesoap:Document"/>
<element name="attributes" nillable="true" type="xsd:anyType"/>
<element name="childElements" nillable="true" type="tns2:Iterator"/>
<element name="children" nillable="true" type="soapenc:Array"/>
<element name="completeAttributes" nillable="true" type="tns3:Attributes"/>
<element name="contentsIndex" type="xsd:int"/>
<element name="dirty" type="xsd:boolean"/>
<element name="elementName" nillable="true" type="xsd:anyType"/>
<element name="encodingStyle" nillable="true" type="xsd:string"/>
<element name="endIndex" type="xsd:int"/>
<element name="envelope" nillable="true" type="tns1:SOAPEnvelope"/>
<element name="fixupDeserializer" nillable="true" type="xsd:anyType"/>
<element name="href" nillable="true" type="xsd:string"/>
<element name="name" nillable="true" type="xsd:string"/>
<element name="namespacePrefixes" nillable="true" type="tns2:Iterator"/>
<element name="namespaceURI" nillable="true" type="xsd:string"/>
<element name="objectValue" nillable="true" type="xsd:anyType"/>
<element name="parentElement" nillable="true" type="xsd:anyType"/>
<element name="prefix" nillable="true" type="xsd:string"/>
<element name="realElement" nillable="true" type="tns1:MessageElement"/>
<element name="recorder" nillable="true" type="tns1:SAX2EventRecorder"/>
<element name="root" type="xsd:boolean"/>
<element name="type" nillable="true" type="xsd:QName"/>
<element name="value" nillable="true" type="xsd:string"/>
<element name="namespaces" nillable="true" type="soapenc:Array"/>
</sequence>
</complexType>
<complexType name="SOAPBodyElement">
<complexContent>
<extension base="tns1:MessageElement">
<sequence/>
</extension>
</complexContent>
</complexType>
<complexType name="SOAPEnvelope">
<complexContent>
<extension base="tns1:MessageElement">
<sequence>
<element name="SAAJEncodingCompliance" type="xsd:boolean"/>
<element name="SOAPConstants" nillable="true" type="xsd:anyType"/>
<element name="body" nillable="true" type="xsd:anyType"/>
<element name="bodyElements" nillable="true" type="apachesoap:Vector"/>
<element name="firstBody" nillable="true" type="tns1:SOAPBodyElement"/>
<element name="header" nillable="true" type="xsd:anyType"/>
<element name="headers" nillable="true" type="apachesoap:Vector"/>
<element name="messageType" nillable="true" type="xsd:string"/>
<element name="schemaVersion" nillable="true" type="xsd:anyType"/>
<element name="soapConstants" nillable="true" type="tns6:SOAPConstants"/>
<element name="trailers" nillable="true" type="apachesoap:Vector"/>
</sequence>
</extension>
</complexContent>
</complexType>
</schema>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.apache.org/xml-soap">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="Vector">
<sequence>
<element name="item" minOccurs="0" maxOccurs="unbounded" type="xsd:anyType"/>
</sequence>
</complexType>
</schema>
</wsdl:types>

<wsdl:message name="getPriceInfoResponse">
</wsdl:message>

<wsdl:message name="getPriceInfoRequest">
<wsdl:part name="requestEnvelope" type="tns1:SOAPEnvelope"/>
<wsdl:part name="responseEnvelope" type="tns1:SOAPEnvelope"/>
</wsdl:message>

<wsdl:portType name="OrderService2">
<wsdl:operation name="getPriceInfo"
parameterOrder="requestEnvelope responseEnvelope">
<wsdl:input name="getPriceInfoRequest"
message="impl:getPriceInfoRequest"/>
<wsdl:output name="getPriceInfoResponse"
message="impl:getPriceInfoResponse"/>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="OrderService2SoapBinding" type="impl:OrderService2">
<wsdlsoap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getPriceInfo">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getPriceInfoRequest">
<wsdlsoap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="OrderService2"/>
</wsdl:input>
<wsdl:output name="getPriceInfoResponse">
<wsdlsoap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="OrderService2"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

<wsdl:service name="OrderService2Service">
<wsdl:port name="OrderService2" binding="impl:OrderService2SoapBinding">
<wsdlsoap:address
location="http://localhost:8080/axis/services/OrderService2"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
未記入
会議室デビュー日: 2005/07/23
投稿数: 12
投稿日時: 2005-11-27 22:45
#コードやWSDLの中身まで追っかけてないので一般的なアドバイスですが・・・
えーと、まずaxisを使用したWebサービスですね。
axisのバージョンを参考情報として挙げておいた方がいいですよ。

そしてaxisが生成するWSDLを完全な物だと思わない方がいいです。
別にaxisがダメというわけではなく、自動生成に完璧を求めない方がいいという意味です。

パスが通っていれば、生成に失敗する理由はWSDLの可能性がかなり高いです。
詳細をみていないので「どこの部分」とは断言できませんが、自分なりに原因を探す上で、
よりシンプルなIFを使ったWSDLで試してみてはどうでしょう?

例えば、intを返す1メソッドのみで動作を確認してみるとかです。
この場合でNGなら、java2wsdlでの生成に問題があるので、
「自動生成しないWSDLを使ったクライアントの生成はどうか?」などでさらに詳細を探れると思います。
(動作するWSDLはネットで拾ってこれますし)

#経験上ですが
intを返す1メソッドでは、環境ができていれば成功してくれるはずです。
大概はWebServiceのIFでサポート外の型を使い、狂ってしまうケースだと思います。
kan
ベテラン
会議室デビュー日: 2002/11/28
投稿数: 55
投稿日時: 2005-11-28 00:41
サーバ側をDocument/LiteralのAPIを使って実装したときは、正しいWSDLを自動生成
することはできないと思います。

SOAPメッセージとなる、SOAPEnvelopeの中身を静的に解析するのは難しいでしょう。

例えば、以下の部分が空になって生成されているのが分かるかと思います。

<wsdl:message name="getPriceInfoResponse">
</wsdl:message>

自動生成されたWSDLに対して、自分でtypesを正しく追加する必要があります。
entama
会議室デビュー日: 2005/11/26
投稿数: 2
投稿日時: 2005-11-29 00:21
kan様

回答ありがとうございます。

>>サーバ側をDocument/LiteralのAPIを使って実装したときは、正しいWSDLを自動生成
>>することはできないと思います。
>>自動生成されたWSDLに対して、自分でtypesを正しく追加する必要があります。
参考になります。WSDLを勉強していろいろ試行してみようと思います。

もしも、Document/LiteralのAPIを使った際のWSDLについて、初心者向けに説明したサイトなどをご存知でしたら、教えていただけると助かります。




未記入様
回答ありがとうございます。
>>よりシンプルなIFを使ったWSDLで試してみてはどうでしょう?
指摘の通りだと思います。単純化して、いろいろやってみます。
1

スキルアップ/キャリアアップ(JOB@IT)