За последние 24 часа нас посетили 15774 программиста и 1664 робота. Сейчас ищут 867 программистов ...

SOAP проблема с setClass()

Тема в разделе "Прочие вопросы по PHP", создана пользователем Eris, 4 дек 2008.

  1. Eris

    Eris Активный пользователь

    С нами с:
    4 дек 2008
    Сообщения:
    2
    Симпатии:
    0
    Доброго времени суток!

    У меня тут 2 класса, которые поставляют веб-сервисы и я хочу сделать так, чтоб для этих двух классов работал один SoapServer, один SoapClient, и был один wsdl файл.
    Логично сделать так:

    $server->setClass("Class1");
    $server->setClass("Class2");
    $server->handle();

    но дело в том, что как только я добавляю Class2, функции Class1 перестают работать, и я получаю ошибку в клиенте при их вызове.

    Предположительно тут дело в namespace-ах, и наверное можно решить проблему, если правильно их использовать. Может у кого-то есть идеи?

    Вот код сервера - server.php:
    Код (Text):
    1.  
    2. $server = new SoapServer("bla.wsdl");
    3.  
    4. $server->setClass("Class1");
    5. $server->setClass("Class2");
    6.  
    7. $server->handle();
    8.  
    9.  
    10. class Class1 {
    11.    public function pow2($a) { return $a * $a; }
    12.    public function pow3($a) { return $a * $a * $a; }
    13. }
    14.  
    15. class Class2 {
    16.    public function pow4($a) { return $a * $a * $a * $a; }
    17. }
    Это клиент client.php:
    Код (Text):
    1.  
    2. $client = new SoapClient("bla.wsdl");
    3.  
    4. echo "2 ^ 2 = " . $client->pow2(2) . "\n";
    5. echo "2 ^ 3 = " . $client->pow3(2) . "\n";
    6. echo "2 ^ 4 = " . $client->pow4(2) . "\n";
    И это wsdl - bla.wsdl
    Код (Text):
    1.  
    2. <?xml version ='1.0' encoding ='UTF-8' ?>
    3. <definitions
    4.  xmlns:class1Ns='http://example.org/Class1'
    5.  xmlns:class2Ns='http://example.org/Class2'
    6.  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
    7.  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
    8.  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
    9.  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
    10.  xmlns='http://schemas.xmlsoap.org/wsdl/'>
    11.  
    12. <message name='pow2Request'>
    13.  <part name='number' type='xsd:float'/>
    14. </message>
    15.  
    16. <message name='pow2Response'>
    17.  <part name='result' type='xsd:float'/>
    18. </message>
    19.  
    20. <message name='pow3Request'>
    21.  <part name='number' type='xsd:float'/>
    22. </message>
    23.  
    24. <message name='pow3Response'>
    25.  <part name='result' type='xsd:float'/>
    26. </message>
    27.  
    28. <message name='pow4Request'>
    29.  <part name='number' type='xsd:float'/>
    30. </message>
    31.  
    32. <message name='pow4Response'>
    33.  <part name='result' type='xsd:float'/>
    34. </message>
    35.  
    36.  
    37.  
    38.  
    39. <portType name='Class1PortType'>
    40.  <operation name='pow2'>
    41.   <input message='class1Ns:pow2Request'/>
    42.   <output message='class1Ns:pow2Response'/>
    43.  </operation>
    44.  <operation name='pow3'>
    45.   <input message='class1Ns:pow3Request'/>
    46.   <output message='class1Ns:pow3Response'/>
    47.  </operation>
    48. </portType>
    49.  
    50. <portType name='Class2PortType'>
    51.  <operation name='pow4'>
    52.   <input message='class2Ns:pow4Request'/>
    53.   <output message='class2Ns:pow4Response'/>
    54.  </operation>
    55. </portType>
    56.  
    57.  
    58.  
    59.  
    60. <binding name='Class1Binding' type='class1Ns:Class1PortType'>
    61.  
    62.  <soap:binding style='rpc'
    63.   transport='http://schemas.xmlsoap.org/soap/http'/>
    64.  
    65.  <operation name='pow2'>
    66.   <soap:operation soapAction='urn:pow2'/>
    67.   <input>
    68.    <soap:body use='literal'/>
    69.   </input>
    70.   <output>
    71.    <soap:body use='literal'/>
    72.   </output>
    73.  </operation>
    74.  
    75.  <operation name='pow3'>
    76.   <soap:operation soapAction='urn:pow3'/>
    77.   <input>
    78.    <soap:body use='literal'/>
    79.   </input>
    80.   <output>
    81.    <soap:body use='literal'/>
    82.   </output>
    83.  </operation>
    84.  
    85. </binding>
    86.  
    87.  
    88.  
    89. <binding name='Class2Binding' type='class2Ns:Class2PortType'>
    90.  
    91.  <soap:binding style='rpc'
    92.   transport='http://schemas.xmlsoap.org/soap/http'/>
    93.  
    94.  <operation name='pow4'>
    95.   <soap:operation soapAction='urn:pow4'/>
    96.   <input>
    97.    <soap:body use='literal'/>
    98.   </input>
    99.   <output>
    100.    <soap:body use='literal'/>
    101.   </output>
    102.  </operation>
    103.  
    104. </binding>
    105.  
    106.  
    107.  
    108. <service name='Class1AndClass2Service'>
    109.  <port name='Class1Port' binding='class1Ns:Class1Binding'>
    110.   <soap:address location='http://localhost/collision/server.php'/>
    111.  </port>
    112.  
    113.   <port name='Class2Port' binding='class2Ns:Class2Binding'>
    114.   <soap:address location='http://localhost/collision/server.php'/>
    115.  </port>
    116. </service>
    117. </definitions>
    Получается, что если откомментировать строку

    $server->setClass("Class2");

    в server.php, то первые два вызова функций:

    echo "2 ^ 2 = " . $client->pow2(2) . "\n";
    echo "2 ^ 3 = " . $client->pow3(2) . "\n";

    будут работать. Ну и понятно, третий вызов даст ошибку.
    А если закомментить

    $server->setClass("Class1");

    и поставить на первое место в клиенте вызов $client->pow4(2), то этот вызов будет работать, а остальные нет. То есть получается, что если использовать setClass(), то на сервере сможет работать только один класс, а мне необходимо, чтобы их было несколько на одном и том же SoapServer-е...

    Уже столько ночей ушло на поиски решения и столько документации напрочитано, но ни фи**. Вот по форумам скитаюсь. Помогите пожалста люди добрые!!