[kansaipm] SOAP::Lite で encodingStyle を指定する方法は?

mishima at momo.so-net.ne.jp mishima at momo.so-net.ne.jp
Fri Jan 3 02:42:37 CST 2003


三嶋@難波です。

みなさん、明けましておめでとうございます。
本年もよろしくお願いいたします。

さて、最近長い休みを利用してSOAPで遊んでいるのですが、
そこでちょっと行き詰まっています。

あれこれ調べたところ、どうやら Perl 側の設定の問題であることが
分かってきたので、こちらで質問させていただきたいと思います。

サーバ側環境:
	Windows2000
	Apache Tomcat 4.1.18
	Apache SOAP 2.3.1

クライアント側環境:
	Cygwin Perl 5.6.1
	SOAP::Lite 0.55

質問内容は、Subject に書いた一点に尽きるのですが、
簡単に背景の説明をしておきます。

■はじめに

Apache SOAP に含まれるサンプルで、サーバ側・クライアント側とも
Java のプログラムを使う場合には問題なく動作します。
サーバ側に Java のサンプルを使い、クライアント側に自作の
Perl スクリプトを使った場合、成功するメソッド呼び出しと、
失敗するメソッド呼び出しがあります。

■失敗するパターン

以下のようなスクリプトを実行すると、
サーバ側で例外が発生します。

====<<スクリプト>>====

#!/usr/bin/perl -w
use strict;
use SOAP::Lite +trace => qw(all);
my $result = SOAP::Lite
    ->uri('urn:AddressFetcher')
    ->proxy('http://localhost:8080/soap/servlet/rpcrouter')
    ->getAllListings();
print $result->result;

====<<発行されるリクエスト>>====

POST http://localhost:8080/soap/servlet/rpcrouter
Accept: text/xml
Accept: multipart/*
Content-Length: 465
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:AddressFetcher#getAllListings"

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  <SOAP-ENV:Body>
    <namesp2:getAllListings xmlns:namesp2="urn:AddressFetcher"/>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<!-- 但し、読み易いよう空白や改行は調整してあります。-->

====<<レスポンス>>====

SOAP Error:SOAP-ENV:Server:java.lang.IllegalArgumentException: No
Serializer found to serialize a &apos;org.w3c.dom.Element&apos; using
encoding style &apos;http://schemas.xmlsoap.org/soap/encoding/&apos;.
(以下省略)

■変更すると良さそうなポイント

Apache SOAP に含まれる Java のクライアント側サンプルでは、
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
とか
    call.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
というような記述により、encodingStyle を適宜指定しています。

試しに上記のリクエストを、

修正前:
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
修正後:
 SOAP-ENV:encodingStyle="http://xml.apache.org/xml-soap/literalxml"

というふうに変更したものを、telnet コマンドでサーバに直接送り込むと、
正しい結果(org.w3c.dom.Elementで構成されたデータをXMLに変換したもの)
が返されます。

<!-- 但し、タグ内に加えた改行は取っておかないと、サーバ側で
     リクエストをうまく parse できないようです。 -->

■質問内容の詳細

そこで、SOAP::Lite が発行するリクエスト内で、SOAP-ENV:Envelope タグの、
SOAP-ENV:encodingStyle 属性の値を指定する方法を知りたいのです。



以上

長くなりましたが、よろしくお願いします。



More information about the Kansai-pm mailing list