#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    Unhappy How to response to WSDL with xml? :confused:


    I don't use the Soapclient and Soapserver functions, because I don't understand as all. I need to do only the server side to return the response.

    When testing have some problem with the xml. Requestor have been trying to work out, but he can't. he can see the response when he hit my service with SOAPUI but once he added the service details to the test service it broke and he can see a response coming.


    If I used a WSDL document, see some path of WSDL below:


    <wsdl:message name="OTA_HotelAvailRQMessage">
    <wsdlart element="wsse:Security" name="Security"/>
    <wsdlart element="ota:OTA_HotelAvailRQ" name="OTA_HotelAvailRQ"/>
    </wsdl:message>
    <wsdl:message name="OTA_HotelAvailRSMessage">
    <wsdlart element="ota:OTA_HotelAvailRS" name="OTA_HotelAvailRS"/>
    </wsdl:message>

    <wsdlperation name="HotelAvailRQ">
    <wsdl:input message="tns:OTA_HotelAvailRQMessage"/>
    <wsdlutput message="tns:OTA_HotelAvailRSMessage"/>
    </wsdlperation>

    How to return the response with invoke a WSDL operation (HotelAvailRQ) of the webservice?



    I get the content and generate the response as the codes below.
    =======================================
    $request = (isset($HTTP_RAW_POST_DATA)) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); //access raw posted data

    $xml = simplexml_load_string(str_replace("SOAP-ENV","soap",$request));
    $xml->registerXPathNamespace('ot', 'urladdress');
    $hotel_ref = $xml->xpath("//ot:HotelRef");
    $hotel_att = $hotel_ref[0]->attributes();
    $hotelcode = $hotel_att['HotelCode'];

    .... then query to database and make the xml string, see some the codes below .....

    $xml = header("Content-type: text/xml charset=UTF-8");
    $xml .= "<soap:Envelope xmlns:soap=\"urladdress\">\n";
    $xml .= "\t<soap:Header xmlns:soap=\"urladdress\">";
    $xml .= "\t</soap:Header>\n";

    $xml .= "\t<soap:Body>\n";
    $xml .= "\t\t<OTA_HotelAvailRS xmlns=\"urladdress\" Version=\"1.0\" TimeStamp=\"".date(DATE_ATOM, time())."\" EchoToken=\"".$token."\">\n";

    $xml .= "\t\t</OTA_HotelAvailRS>\n";
    $xml .= "\t</soap:Body>\n";
    $xml .= "</soap:Envelope>";
    echo $xml;
    =======================================



    or I should be use the soapserver function below.
    =================================
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new SoapServer("urladdress");
    $server->addFunction("HotelAvailRQ");
    $server->handle();

    function HotelAvailRQ() {
    .... return the response

    }
    =======================================

    That is possible or not? Could you please anybody help me
  2. #2
  3. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    501
    Rep Power
    127
    Oh if only I had full access to my past code right now. I became quite the SOAP guru back in the day, but it's been so long that I'd have to reference what I'd made then to be useful.

    For the moment, though, I'd definitely recommend you use SoapServer, but also note: WSDL structure is everything. There are a lot of options in how a WSDL can be written, but one wrong decision can require a lot of extra work from the server and clients both.

    I'll try to remember to look up some of my stuff this evening to share.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    26
    Yes, it's possible to serve SOAP responses using the SoapServer class from SOAP extension; you can and should do that, instead of manually constructing an XML response. Do you have any specific question about how to work with SoapServer?
    PHP Code:
    function HotelAvailRQ() {
    .... return 
    the response

    }

    if ( (isset(
    $_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']=='POST' && isset($GLOBALS['HTTP_RAW_POST_DATA']))
       ||(isset(
    $_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'],'wsdl')==0) ){
        
    $server = new SoapServer("urladdress");
        
    $server->addFunction("HotelAvailRQ");
        if (isset(
    $GLOBALS['HTTP_RAW_POST_DATA'])) {
            
    $server->handle();
        }
        else {
            
    // you could print your WSDL here so requests ending with "?wsdl" can read it
        
    }

  6. #4
  7. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    501
    Rep Power
    127
    Taken from one of my old SOAP APIs and generalized a bit. Not tested, but should be at least close to working...

    PHP Code:
    $server = new SoapServer($wsdlAddress,array("features"=>SOAP_SINGLE_ELEMENT_ARRAYS));
    $server->setClass("SomeClass");
    $server->handle();

    class 
    SomeClass {
        public function 
    DoSomething($obj){
            
    $value $obj->ValueToReturn;
            return array(
    "Value"=>$value);
        }

    And I can't put up my WSDL example since the forums think I'm adding "too many images". Grr...
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0
    Thank you very mush for all reply the solutions. I'm new account, couldn't post the url link. I'm Thai, sorry If not good in English.

    When the requestor (Siteminder.com) testing via SOPUI have some problem, because I not used to call the HotelAvailRQ operation on WSDL

    WSDL: h22ps://smtpi.siteminder.com/siteconnect/services/siteconnect.wsdl


    Requester to POST my service with a raw request like the below:

    POST h22p://mysoapserver.url/OTA_RetrieveRooms.php HTTP/1.1
    Accept-Encoding: gzip,deflate
    Content-Type: text/xml;charset=UTF-8
    SOAPAction: "h22p://###.siteminder.com.au/siteconnect/HotelAvailRQ"

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="h22p://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header xmlns:SOAP-ENV="h22p://schemas.xmlsoap.org/soap/envelope/">
    <wsse:Security xmlns:wsse="h22p://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soap="h22p://schemas.xmlsoap.org/soap/envelope/" soap:mustUnderstand="1">
    <wsse:UsernameToken>
    <wsse:Username>siteconnecttest</wsse:Username>
    <wsse:Password Type="h22p://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">tsettcennonetis</wsse:Password>
    </wsse:UsernameToken>
    </wsse:Security>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body xmlns:SOAP-ENV="h22p://schemas.xmlsoap.org/soap/envelope/">
    <OTA_HotelAvailRQ xmlns="h22p://###.opentravel.org/OTA/2003/05" AvailRatesOnly="true" EchoToken="471277b3-5b1f-4d12-9a08-7792f4810879" TimeStamp="2013-06-26T15:15:48+10:00" Version="1.0">
    <AvailRequestSegments>
    <AvailRequestSegment AvailReqType="Room">
    <HotelSearchCriteria>
    <Criterion>
    <HotelRef HotelCode="12345"/>
    </Criterion>
    </HotelSearchCriteria>
    </AvailRequestSegment>
    </AvailRequestSegments>
    </OTA_HotelAvailRQ>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    I get POST service with a raw request from Sideminder as the above with $HTTP_RAW_POST_DATA and get the HotelCode to query my database and prepare the response as the following link

    h22ps://siteminder.atlassian.net/wiki/display/SITECONNECT/Retrieve+Rooms


    @dmittner: To invoke the operation on WSDL can be the class or the function right?

    @mod_speling: follow to HotelAvailRQ operation on WSDL. The HotelAvailRQ function should be receive the parameter or not, I don't know what is the client to calling this function.

    Thank you kindly.

IMN logo majestic logo threadwatch logo seochat tools logo