How to Create Function return particular XML Format in Request or Return

Help
hermes1986
2013-09-11
2013-09-12
  • hermes1986

    hermes1986 - 2013-09-11

    Hi Fellows, i am new to Both PHP and NuSoap. And now i have a problem. I want to create a webservice that have a function called OTA_HotelAvailRQ, but i don't know how to produce this SOAP request below :

    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
      <env:Header>
        <wsse:Security>
    
        </wsse:Security>
      </env:Header>
      <env:Body>
        <OTA_HotelAvailRQ Version='1.0' TimeStamp=? EchoToken=?>
          <AvailRequestSegments>
            <AvailRequestSegment AvailReqType='Room'>
              <HotelSearchCriteria>
                <Criterion>
                  <HotelRef HotelCode='Insert HotelCode'/>
                </Criterion>
              </HotelSearchCriteria>
            </AvailRequestSegment>
          </AvailRequestSegments>
        </OTA_HotelAvailRQ>
      </env:Body>
    </env:Envelope>
    

    and to produce this SOAP Response - OTA_HotelAvailRS ( as the response of HotelAvailRQ):

    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
          <env:Header>
    
        <wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
          <wsse:UsernameToken>
            <wsse:Username>USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">SECRET</wsse:Password>
          </wsse:UsernameToken>
        </wsse:Security>
    
      </env:Header>
      <env:Body>
        <OTA_HotelAvailRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="1.0" TimeStamp="2005-08-01T09:30:47+02:00" EchoToken="abc123">
          <Success/>
          <RoomStays>
            <RoomStay>
              <RoomTypes>
                <RoomType RoomTypeCode="VAL1">
                  <RoomDescription Name="DESC1"/>
                </RoomType>
              </RoomTypes>
            </RoomStay>
            <RoomStay>
              <RoomTypes>
                <RoomType RoomTypeCode="VAL2">
                  <RoomDescription Name="DESC2"/>
                </RoomType>
              </RoomTypes>
            </RoomStay>
            <RoomStay>
              <RoomTypes>
                <RoomType RoomTypeCode="VAL3">
                  <RoomDescription Name="DESC3"/>
                </RoomType>
              </RoomTypes>
            </RoomStay>
          </RoomStays>
        </OTA_HotelAvailRS>
      </env:Body>
    </env:Envelope>
    

    and i need exactly the same format as written above..
    i hope somebody able to help me solve this problem, and many thanks in advance

     
    Last edit: hermes1986 2013-09-11
    • hermes1986

      hermes1986 - 2013-09-12

      the problem is partially solved now. i think nuSOAP is very helpful, i write PHP code shown below, and the 'SOAP request' problem is partially solved.

          <?php
          require_once('lib/nusoap.php');
      
          $server = new nusoap_server;
      
          $server->configureWSDL('server','http://localhost/myweb');
      
          $server->wsdl->schemaTargetNamespace = 'http://localhost/myweb';
      
          $server->wsdl->addComplexType(
              'AvailRequestSegments',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'AvailRequestSegment' => array('name' => 'AvailRequestSegment', 'type' => 'tns:AvailRequestSegment')
                     )
          );
      
          $server->wsdl->addComplexType(
              'AvailRequestSegment',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'AvailReqType'=>array('name'=>'AvailReqType','type'=>'xsd:string','value'=>'Room'),
                  'HotelSearchCriteria' => array('name' => 'HotelSearchCriteria', 'type' => 'tns:HotelSearchCriteria')
                     )
          );
      
          $server->wsdl->addComplexType(
              'HotelSearchCriteria',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'Criterion' => array('name' => 'Criterion', 'type' => 'tns:Criterion')
                     )
          );
      
          $server->wsdl->addComplexType(
              'Criterion',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'HotelRef' => array('name' => 'HotelRef', 'type' => 'tns:HotelRef')
                     )
          );
      
          $server->wsdl->addComplexType(
              'HotelRef',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'HotelCode' => array('name' => 'HotelCode', 'type' => 'xsd:string')
                     )
          );
      
          /*---------------------------segment response---------------------------------------------*/
      
          $server->wsdl->addComplexType(
              'RoomStays',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'RoomStay' => array('name' => 'RoomStay', 'type' => 'tns:RoomStay')
                     )
          );
      
          $server->wsdl->addComplexType(
              'RoomStay',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'RoomTypes' => array('name' => 'RoomTypes', 'type' => 'tns:RoomTypes')
                     )
          );
      
          $server->wsdl->addComplexType(
              'RoomTypes',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'RoomType' => array('name' => 'RoomType', 'type' => 'tns:RoomType')
                     )
          );
      
          $server->wsdl->addComplexType(
              'RoomType',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'RoomTypeCode'=>array('name'=>'RoomTypeCode','type'=>'xsd:string'),
                  'RoomDescription' => array('name' => 'RoomDescription', 'type' => 'tns:RoomDescription')
                     )
          );
      
          $server->wsdl->addComplexType(
              'RoomDescription',
              'complexType',
              'struct',
              'all',
              '',
              array(
                  'Name' => array('name' => 'Name', 'type' => 'xsd:string')
                     )
          );
      
          $server->register('OTA_HotelAvailRQ',
             array('AvailRequestSegments'=>'tns:AvailRequestSegments'),
             array('RoomStays'=>'tns:RoomStays'),
             'http://localhost/myweb',
             'http://localhost/myweb#SayHello');
      
          function OTA_HotelAvailRQ($param)
          {
                     return array(
            'success'=>'success',
            'RoomTypeCode'=>'SGL',
            'Name'=>'single room'
           );    
          }
      
          $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
      
          $server->service($HTTP_RAW_POST_DATA);
      ?>
      

      and the rest of my problem is, how to insert 'some data' into complex types i created, i have try this

          return array(
            'success'=>'success',
            'RoomTypeCode'=>'SGL',
            'Name'=>'single room'
           );
      

      but it won't work, and the SOAP response is :

          <SOAP-ENV Envelope SOAP-ENV:encoding xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://localhost/myweb">
             <SOAP-ENV:Body>
                <ns1:OTA_HotelAvailRQResponse xmlns:ns1="http://localhost/myweb">
                   <RoomStays xsi:type="tns:RoomStays"/>
                </ns1:OTA_HotelAvailRQResponse>
             </SOAP-ENV:Body>
          </SOAP-ENV:Envelope>
      

      and finally the last thing i have to solve is, i don't know how to put AvailReqType="Room" attribute inside the < AvailRequestSegment> as shown below

          <AvailRequestSegment AvailReqType="Room">
      

      it's very appreciate if somebody like to help me... thanks in advance..

       

Log in to post a comment.