14

同じ名前の要素とcomplexTypeを含むいくつかの異なるWSDLファイルに遭遇しました。たとえば、http ://soap.search.msn.com/webservices.asmx? wsdlには、「SearchResponse」という名前の2つのエンティティがあります。

このシナリオでは、SoapClient()の「classmaps」オプションを使用してこれらのエンティティをPHPクラスに適切にマップする方法を理解できません。

PHPのマニュアルには次のように書かれています。

classmapオプションを使用して、一部のWSDLタイプをPHPクラスにマップできます。このオプションは、WSDLタイプをキーとして、PHPクラスの名前を値として持つ配列である必要があります。

残念ながら、同じキー('SearchResponse')を持つ2つのWSDLタイプがあるため、2つのSearchResponseエンティティを区別して対応するPHPクラスに割り当てる方法がわかりません。

たとえば、WSDLの例の関連するスニペットは次のとおりです。

<xsd:complexType name="SearchResponse">
    <xsd:sequence>
        <xsd:element minOccurs="1" maxOccurs="1" name="Responses" type="tns:ArrayOfSourceResponseResponses"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:element name="SearchResponse">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element minOccurs="1" maxOccurs="1" name="Response" type="tns:SearchResponse"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

クラスマップキーが同じであるため、明らかに機能しないPHPは次のとおりです。

<?php $server = new SoapClient("http://soap.search.msn.com/webservices.asmx?wsdl", array('classmap' => array('SearchResponse' => 'MySearchResponseElement', 'SearchResponse' => 'MySearchResponseComplexType'))); ?>

解決策を探していると、Java Web Servicesが、「Element」または「ComplexType」エンティティにカスタムサフィックスを指定できるようにすることでこれを処理していることがわかりました。

http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html#wp149350

ですから、今のところ、PHPのSoapClientでそれを行う方法はないように感じますが、誰かがアドバイスを提供できるかどうか知りたいです。FWIW、リモートWDSLを編集できません。

何か案は???

4

1 に答える 1

7

これは頭​​から離れていますが、両方のSearchResponseタイプをMY_SearchResponseにマップして、2つの違いを抽象化してみることができると思います。ぎこちないですが、多分このようなものですか?

<?php
//Assuming SearchResponse<complexType> contains SearchReponse<element> which contains and Array of SourceResponses
//You could try abstracting the nested Hierarchy like so:
class MY_SearchResponse
{
   protected $Responses;
   protected $Response;

   /**
    * This should return the nested SearchReponse<element> as a MY_SearchRepsonse or NULL
    **/
   public function get_search_response()
   {
      if($this->Response && isset($this->Response))
      {
         return $this->Response; //This should also be a MY_SearchResponse
      }
      return NULL;
   }

   /**
    * This should return an array of SourceList Responses or NULL
    **/
   public function get_source_responses()
   {
      //If this is an instance of the top SearchResponse<complexType>, try to get the SearchResponse<element> and it's source responses
      if($this->get_search_response() && isset($this->get_search_response()->get_source_responses()))
      {
         return $this->get_search_response()->get_source_responses();
      }
      //We are already the nested SearchReponse<element> just go directly at the Responses
      elseif($this->Responses && is_array($this->Responses)
      {
         return $this->Responses;
      }
      return NULL;
   }
}

class MY_SourceResponse
{
  //whatever properties SourceResponses have
}

$client = new SoapClient("http:/theurl.asmx?wsdl", array('classmap' => array('SearchResponse' => 'MY_SearchResponse', 'SourceResponse' => 'MY_SourceResponse')));
于 2010-10-08T16:11:11.170 に答える