Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1820
  • Last Modified:

Problem creating SOAP Request using PHP SoapClient

Hello,
I have a problem creating a SOAP Request using PHP SoapClient.
Request works fine from SOAP UI but fails from PHP SoapClient
Bellow are code extract of:
1.XML Request in SoapUI
2.XML Response in SoapUI
3.PHP Request
4.PHP Output
XML Request in SoapUI:
======================
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:opp="urn:crmondemand/ws/ecbs/opportunity/" 
                  xmlns:quer="urn:/crmondemand/xml/Opportunity/Query">
   <soapenv:Header>
      <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/xx/secext">
         <wsse:UsernameToken>
            <wsse:Username>HIDDEN</wsse:Username>
            <wsse:Password>HIDDEN</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <opp:OpportunityQueryPage_Input>
         <quer:ListOfOpportunity>
            <!--Optional:-->
            <quer:Opportunity>
               <quer:AccountName sortorder="Name" sortsequence="">LIKE '*'</quer:AccountName>
            </quer:Opportunity>
         </quer:ListOfOpportunity>
      </opp:OpportunityQueryPage_Input>
   </soapenv:Body>
</soapenv:Envelope>


XML Response in SoapUI:
=======================
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body>
      <ns:OpportunityQueryPage_Output xmlns:ns="urn:crmondemand/ws/ecbs/opportunity/">
         <ListOfOpportunity lastpage="false" xmlns="urn:/crmondemand/xml/Opportunity/Data">
            <Opportunity>
               <AccountName>Action Rentals</AccountName>
            </Opportunity>
            <Opportunity>
               <AccountName>Bay Advertising</AccountName>
            </Opportunity>
            <Opportunity>
               <AccountName>United Enterprises</AccountName>
            </Opportunity>
         </ListOfOpportunity>
      </ns:OpportunityQueryPage_Output>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

PHP Request:
============
<?php
    $client = new SoapClient("http://localhost/ondemand/wsdl/v2/Opportunity.wsdl", array('trace' => 1));

    //generate soap header
    $wsse_ns = 'http://schemas.xmlsoap.org/ws/2002/xx/secext';
    $headerbody = array('UsernameToken' => array('Username' => 'HIDDEN','Password' => 'HIDDEN'));
    $header = new SoapHeader($wsse_ns, 'Security', $headerbody);
    $client->__setSoapHeaders(array($header));
    $requestbody = array(
        'ListOfOpportunity' => array(
            'Opportunity' => array(
                'AccountName' => "LIKE '*'"
            )
        )
    );
    try {
        $response = $client->OpportunityQueryPage($requestbody);
        ?>Success Response:<hr><pre><?php var_dump($response)?></pre><?php
    } catch (SoapFault $fault) {
        ?>Fault:<hr><pre><?php var_dump($fault)?></pre><?php
    }

?>

PHP Output:
===========
object(SoapFault)#4 (10) {
  ["message":protected]=>
  string(6) "Server"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(30) "C:\www\ondemand\index.php"
  ["line":protected]=>
  int(33)
  ["trace":"Exception":private]=>
  array(2) {
    [0]=>
    array(4) {
      ["function"]=>
      string(6) "__call"
      ["class"]=>
      string(10) "SoapClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(20) "OpportunityQueryPage"
        [1]=>
        array(1) {
          [0]=>
          array(1) {
            ["ListOfOpportunity"]=>
            array(1) {
              ["Opportunity"]=>
              array(1) {
                ["AccountName"]=>
                string(8) "LIKE '*'"
              }
            }
          }
        }
      }
    }
    [1]=>
    array(6) {
      ["file"]=>
      string(30) "C:\wamp\www\ondemand\index.php"
      ["line"]=>
      int(33)
      ["function"]=>
      string(20) "OpportunityQueryPage"
      ["class"]=>
      string(10) "SoapClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(1) {
        [0]=>
        array(1) {
          ["ListOfOpportunity"]=>
          array(1) {
            ["Opportunity"]=>
            array(1) {
              ["AccountName"]=>
              string(8) "LIKE '*'"
            }
          }
        }
      }
    }
  }
  ["previous":"Exception":private]=>
  NULL
  ["faultstring"]=>
  string(6) "Server"
  ["faultcode"]=>
  string(11) "soap:Server"
  ["detail"]=>
  object(stdClass)#3 (2) {
    ["ErrorCode"]=>
    string(13) "SBL-ODU-01006"
    ["ErrorMessage"]=>
    string(51) "Internal Error: Session is not available. Aborting."
  }
}

Open in new window

0
deve-lopez
Asked:
deve-lopez
1 Solution
 
Ray PaseurCommented:
This is going to sound like a really lame answer, but it may be helpful to you.

Don't use SOAP.

Instead learn about RESTful interfaces - they are so much easier to get right, that some of my colleagues say SOAP is the devil.  I won't go quite that far, but I will say that REST is heavenly in comparison to SOAP.  One of the best REST description and examples is available in the Yahoo Geocoder API.
http://developer.yahoo.com/maps/rest/V1/geocode.html

Best of luck with your project, ~Ray
0
 
deve-lopezAuthor Commented:
Thanks for the suggestion but the system I need to call only implements SOAP and will not change any time soon (enterprise grade web services)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now