SOAP応答結果にnamespaceを指定する方法 - PHPプロ!Q&A掲示板

2796

  • 0P

SOAP応答結果にnamespaceを指定する方法

質問日時 / 2010年7月1日 12:44    回答数 / 5件

Questioner:  sebisawa  このエントリーをはてなブックマークに追加 

キーワード / SOAP    WSDL    namespace   

PHPでSOAPサーバの構築をしているのですが、各要素にnameスペースのprefixが入ってしまうため、これを消す方法を調べています。もしご存知の方がいらっしゃれば、アドバイスをいただけると幸いです。

現在のSOAP応答結果
  1. <SOAP-ENV:Envelope
  2.   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  3.   xmlns:ns1="http://test.com/">
  4.   <SOAP-ENV:Body>
  5.     <ns1:ElementTrendCompareResponse>
  6.       <ns1:label>2010/04</ns1:label>
  7.       <ns1:value>814859</ns1:value>
  8.     </ns1:ElementTrendCompareResponse>
  9.   </SOAP-ENV:Body>
  10. </SOAP-ENV:Envelope>

期待するSOAP応答結果(細かい点はいいとして、「ns1:」という文字を各要素から消したいです)
  1. <SOAP-ENV:Envelope
  2.   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  3.   <SOAP-ENV:Body>
  4.     <ElementTrendCompareResponse xmlns="http://test.com">
  5.       <label>2010/04</label>
  6.       <value>814859</value>
  7.     </ElementTrendCompareResponse>
  8.   </SOAP-ENV:Body>
  9. </SOAP-ENV:Envelope>

WSDLとプログラムの内容は次のとおりです。
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  3.                   xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
  4.                   xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  5.                   xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
  6.                   xmlns:tns="http://test.com/"
  7.                   xmlns:s="http://www.w3.org/2001/XMLSchema"
  8.                   targetNamespace="http://test.com/"
  9.                   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  10.   <wsdl:types>
  11.   <!-- type -->
  12.     <s:schema elementFormDefault="qualified" targetNamespace="http://test.com/">
  13.       <!-- request -->
  14.       <s:element name="ElementTrendCompareRequest">
  15.         <s:complexType>
  16.           <s:sequence>
  17.             <s:element minOccurs="0" maxOccurs="1" name="month" type="s:string" />
  18.           </s:sequence>
  19.         </s:complexType>
  20.       </s:element>
  21.       <!-- response -->
  22.       <s:element name="ElementTrendCompareResponse">
  23.         <s:complexType>
  24.           <s:sequence>
  25.             <!-- current period -->
  26.             <s:element minOccurs="1" maxOccurs="1" name="label" type="s:string" />
  27.             <s:element minOccurs="1" maxOccurs="1" name="value" type="s:int" />
  28.           </s:sequence>
  29.         </s:complexType>
  30.       </s:element>
  31.     </s:schema>
  32.   </wsdl:types>
  33.   <!-- message -->
  34.   <wsdl:message name="MessageTrendCompareRequest">
  35.     <wsdl:part name="parameters" element="tns:ElementTrendCompareRequest" />
  36.   </wsdl:message>
  37.   <wsdl:message name="MessageTrendCompareResponse">
  38.     <wsdl:part name="parameters" element="tns:ElementTrendCompareResponse" />
  39.   </wsdl:message>
  40.   <!-- port -->
  41.   <wsdl:portType name="PortTypeTrendSoap">
  42.     <wsdl:operation name="OperationTrendCompare">
  43.       <wsdl:input message="tns:MessageTrendCompareRequest" />
  44.       <wsdl:output message="tns:MessageTrendCompareResponse" />
  45.     </wsdl:operation>
  46.   </wsdl:portType>
  47.   <!-- binding -->
  48.   <wsdl:binding name="BindingTrendSoap" type="tns:PortTypeTrendSoap">
  49.     <wsdl:operation name="OperationTrendCompare">
  50.       <wsdl:input>
  51.         <soap:body use="literal" />
  52.       </wsdl:input>
  53.       <wsdl:output>
  54.         <soap:body use="literal" />
  55.       </wsdl:output>
  56.     </wsdl:operation>
  57.     <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
  58.   </wsdl:binding>
  59.   <!-- service -->
  60.   <wsdl:service name="ServiceTrend">
  61.     <wsdl:port name="PortTrendSoap" binding="tns:BindingTrendSoap">
  62.       <soap:address location="http://hostname/soap/qa/Server.php" />
  63.     </wsdl:port>
  64.   </wsdl:service>
  65. </wsdl:definitions>

サーバ側プログラム
  1. <?php
  2.  
  3. ini_set('soap.wsdl_cache_enabled''0');
  4. ini_set('soap.wsdl_cache_ttl''0');
  5.  
  6. define( "WSDL_PATH""./test.wsdl" );
  7.  
  8. /*=======================================================================
  9.  Soap Operations
  10. =======================================================================*/
  11.  
  12. function OperationTrendCompare($param){
  13.  
  14.     // レスポンスの作成
  15.     return array(
  16.         "label" => "2010/04",
  17.         "value" => 814859,
  18.     );
  19. }
  20.  
  21. /*=======================================================================
  22.  Soap Server Main function
  23. =======================================================================*/
  24.  
  25. // Soap server
  26. $server = new SoapServer( WSDL_PATH );
  27.  
  28. $server->addFunction("OperationTrendCompare");
  29.  
  30. if( $_SERVER["REQUEST_METHOD"] == "POST" ){
  31.     $server->handle();
  32. } else {
  33.     echo "このSOAPサーバのメソッド:  ";
  34.     $functions = $server->getFunctions();
  35.     foreach( $functions as $func ){
  36.         echo $func . " ";
  37.     }
  38. }
  39.  
  40. ?>

以上よろしくお願いいたします。

この質問への意見の募集は締め切られ、ポイントは既に配分されました。
意見を投稿することはできますが、ポイントを受け取ることはできません。



ツリー一覧

┣A01pannna# 直接の回答ではありません サーバを立てて色々や
┃┣A01-1sebisawaコメントありがとうございます。ちょっとスキル的にパ
┃┗A01-2sebisawaコメントありがとうございます。ちょっとスキル的にパ
┗A02magicflute2PHPマニュアルの[User Contributed Notes]では、 文
 ┗A02-1sebisawaコメントありがとうございます。確かに下記のソースで

回答一覧

並び替え:

A01
answererpannna [7月1日 16:06] (最終編集:7月1日 16:07)

# 直接の回答ではありません

サーバを立てて色々やってみましたが、勝手にprefixがついてしまうようですね。
オプション等で外せるのかと調べてはみたのですが見当たりませんでした。

ソースでいうと、/ext/soap/soap.cがこのあたりの処理をしているようなので、
パッチを作るなどすればいけるのではないかなと思うのですが
SOAPはクライアントしかやったことがなく詳しくは私も分かっていません。

お役に立てず申し訳ないです。

この意見に回答する

ツリーへ TOPへ

A01-1
replyersebisawa [7月2日 10:21]

コメントありがとうございます。ちょっとスキル的にパッチまで作成するのは厳しいです。

この意見に回答する

ツリーへ TOPへ

A01-2
replyersebisawa [7月2日 10:21]

コメントありがとうございます。ちょっとスキル的にパッチまで作成するのは厳しいです。

この意見に回答する

ツリーへ TOPへ

A02 満足
answerermagicflute2 [7月1日 23:59]

PHPマニュアルの[User Contributed Notes]では、
文字列置換のコールバック関数を用意して、
$server->handle();をob_startob_end_flushでサンドしてますね。

http://jp.php.net/manual/ja/ref.soap.php

この意見に回答する

ツリーへ TOPへ

A02-1
replyersebisawa [7月2日 10:20]

コメントありがとうございます。確かに下記のソースでprefixを消すことができました。SOAPクライアント側も問題なく読み込めるようです。


  1. <?php
  2.  
  3. ini_set('soap.wsdl_cache_enabled''0');
  4. ini_set('soap.wsdl_cache_ttl''0');
  5.  
  6. define( "WSDL_PATH""./test.wsdl" );
  7.  
  8. /*=======================================================================
  9.  Soap Operations
  10. =======================================================================*/
  11.  
  12. function OperationTrendCompare($param){
  13.  
  14.     // レスポンスの作成
  15.     return array(
  16.         "label" => "2010/04",
  17.         "value" => 814859,
  18.     );
  19. }
  20.  
  21. /*=======================================================================
  22.  Soap Server Main function
  23. =======================================================================*/
  24.  
  25. // callback to remove "ns1" prefix
  26. function callback($input) {
  27.     $input = preg_replace('/<(\/*)ns1:/''<$1'$input);
  28.  
  29.     return ($input);
  30. }
  31.  
  32. // Soap server
  33. $server = new SoapServer( WSDL_PATH );
  34.  
  35. $server->addFunction("OperationTrendCompare");
  36.  
  37. if( $_SERVER["REQUEST_METHOD"] == "POST" ){
  38.     ob_start('callback');
  39.     $server->handle();
  40.     ob_end_flush();
  41. } else {
  42.     echo "このSOAPサーバのメソッド:  ";
  43.     $functions = $server->getFunctions();
  44.     foreach( $functions as $func ){
  45.         echo $func . " ";
  46.     }
  47. }
  48.  
  49. ?>

この意見に回答する

ツリーへ TOPへ

<<質問一覧へ



Pick Up Q&A

Q
動的なURLを静的に見せる方法
 このエントリーをはてなブックマークに追加 
A
普通に考えて、mod_rewrite でしょうね。 http://www.nishishi.com/blog/2006/01/mod_rewrite_url.html...

>>続きを読む

GETのままでは検索エンジンのロボットが拾ってくれなかったためにSEO対策として有効だと言われていますね。

▲解説者:岡本(アシアル株式会社 教育コーディネーター兼 システムエンジニア)