?
Solved

Problem creating SOAP Request using PHP SoapClient

Posted on 2010-01-12
2
Medium Priority
?
1,780 Views
Last Modified: 2013-11-18
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
Comment
Question by:deve-lopez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26323234
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
 

Accepted Solution

by:
deve-lopez earned 0 total points
ID: 26338487
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question