Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with WSDL Client Submission

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
0
0
US
OK, writing a PHP routine to process HTML form via a web service and push back the response.

I am able to establish a connection, validate user credentials but, I cannot get the most important part to work, processing the form and getting a response back.

The WSDL server expects (sample as documented)
Code:
<s:Envelope xmlns:s="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/">[/URL]
   <s:Body>
      <GetLTLRates xmlns="[URL unfurl="true"]http://tempuri.org/">[/URL]
         <ltlRequest xmlns:a="[URL unfurl="true"]http://schemas.datacontract.org/2004/07/LogisticsAppSuite.RatingEngine.DataModels"[/URL] xmlns:i="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">[/URL]
           <a:AccessorialCodes>
               <!--Zero or more repetitions:-->
               <a:string>IDC</a:string>
            </a:AccessorialCodes>
            <a:ClientCode>xxxxx</a:ClientCode>
            <a:DestCity>CANTON</a:DestCity>
            <a:DestCountry>US</a:DestCountry>
            <a:DestState>CT</a:DestState>
            <a:DestZip>06019</a:DestZip>
            <a:IsBatch>false</a:IsBatch>
            <a:Miles>0</a:Miles>
            <a:OrigCity>BRISTOL</a:OrigCity>
            <a:OrigCountry>US</a:OrigCountry>
            <a:OrigState>CT</a:OrigState>
            <a:OrigZip>06010</a:OrigZip>
            <a:ProfileCode>xxxxx</a:ProfileCode>
            <a:RequestId>5bd55929-94e4-4399-8986-2397f68a2583</a:RequestId>
            <a:Route i:nil="true"/>
            <a:SCAC i:nil="true"/>
            <a:ServiceLevelCode i:nil="true"/>
            <a:ShipmentDate>2014-07-08</a:ShipmentDate>
            <a:Shipments>
               <a:Shipment>
                  <a:Class>50</a:Class>
                  <a:HazMat>false</a:HazMat>
                  <a:Height i:nil="true"/>
                  <a:Length i:nil="true"/>
                  <a:NMFC i:nil="true"/>
                  <a:Pallets>1</a:Pallets>
                  <a:Pieces i:nil="true"/>
                  <a:Weight>1000</a:Weight>
                  <a:Width i:nil="true"/>
               </a:Shipment>
            </a:Shipments>
            <a:SrvToken>BBBBBB</a:SrvToken>
            <a:UsrToken>DDDDDD</a:UsrToken>
            <a:ZoneCode i:nil="true"/>
         </ltlRequest>
      </GetLTLRates>
   </s:Body>
</s:Envelope>

I am sending
Code:
Array
(
    [ClientCode] => AAAA
    [ProfileCode] => AAAA
    [DestCity] => BEATRICE
    [DestCountry] => USA
    [DestState] => AL
    [DestZip] => 36425
    [isBatch] => false
    [OrigCity] => MINEOLA
    [OrigCountry] => USA
    [OrigState] => NY
    [OrigZip] => 11501
    [RequestId] => 5671a8cea5519
    [ShipmentDate] => 2015-12-18
    [Shipments] => Array
        (
            [Shipment] => Array
                (
                    [0] => Array
                        (
                            [Class] => 50
                            [HazMat] => false
                            [Height] => 40
                            [Length] => 40
                            [Pallets] => 1
                            [Pieces] => 40
                            [Weight] => 360
                            [Width] => 40
                        )

                    [1] => Array
                        (
                            [Class] => 50
                            [HazMat] => false
                            [Height] => 40
                            [Length] => 72
                            [Pallets] => 2
                            [Pieces] => 52
                            [Weight] => 420
                            [Width] => 40
                        )

                )

        )

    [SrvToken] => BBBBBBBB
    [UsrToken] => DDDDDDDD
)

I am getting the error that reads
Code:
Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] Object reference not set to an instance of an object.

Not sure why and cannot find an answer thus far and after a whole day, I figure I reach out to you all and see if one of you have had an identical experience and offer some guidance.

thank you all in advance for your help!



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
And, this being the PHP forum .... .... Where is the PHP code?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
So how are you sending that array?

Usually web services have methods you invoke to send info over to them.

What are the definitions for these methods?



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Here is the PHP class
Code:
class SaaS {
    function SaaS() { 
        $this->userid   = 'useridasgiven';
        $this->userpwd  = 'passwordasgiven';
        $this->srvtoken= 'tokenasgiven';
    }
    function init() { 
        $this->userid   = 'useridasgiven';
        $this->userpwd  = 'passwordasgiven';
        $this->srvtoken= 'tokenasgiven';
    }
    function action($action='', $link='', $userToken='', $data='') 
    {
        $this->init();
        switch (strtoupper($action)) {
        case 'LINK':
            // For Sandbox Mode, Please Use:
            $link = new SoapClient("[URL unfurl="true"]https://doman-name.com:####/page.svc?WSDL");[/URL]

            // For Production Mode, Please Use:
            $link = new SoapClient("[URL unfurl="true"]https://doman-name.com/page.svc?WSDL");[/URL]
            return($link);
            break;
        case 'LOGIN':
            if($link == '') { $link=$this->action('link'); }
            /* Set parameters for the request */
            $params = array(
              "userName" => $this->userid,
              "password" => $this->userpwd,
              "srvToken" => $this->srvtoken
            );
            $resp=$link->Login($params);
            return($resp->LoginResult);                  // Returns userToken
            break;
        case 'PROFILE':
            if($link == '') { $link=$this->action('link'); }
            if($userToken == '') { $userToken=$this->action('login',$link); }
            /* Set parameters for the request */
            $params = array(
              "userToken" => $userToken,
              "srvToken" => $this->srvtoken
            );
            $resp=$link->GetProfiles($params);
            return($resp->ProfileCode);      // Returns ProfileCode
            break;
        case 'LTLRATE':
            if($link == '') { $link=$this->action('link'); }
            if($userToken == '') { $userToken=$this->action('login',$link,'',''); }
            echo 'Getting Rate ...<br />'; //debug
            echo 'userToken: '.$userToken.'<br />'; //debug
            $shipments=array();
// there can be up to 5 line items ... shipments construct
            for($x=0; $x<5; $x++) {
                if($_REQUEST['class'][$x] != '') {
                    if($_REQUEST['weight'][$x] != '') {
                        $shipments['Shipment'][$x]=array(
                            'Class'=>$_REQUEST['class'][$x],
                            'HazMat'=>( ($_REQUEST['hazmat'][$x] != '')?'true':'false' ),
                            'Height'=>$_REQUEST['height'][$x],
                            'Length'=>$_REQUEST['length'][$x],
                            'Pallets'=>$_REQUEST['pallets'][$x],
                            'Pieces'=>$_REQUEST['pieces'][$x],
                            'Units'=>$_REQUEST['units'][$x],
                            'Weight'=>$_REQUEST['weight'][$x],
                            'Width'=>$_REQUEST['width'][$x],
                            'NMFC'=>'',
                            'CubicFeet'=>$_REQUEST['cubicfeet'][$x]
                        );
                    }
                }
            }
            echo 'Set shipments parameters to: <br />'; //debug
            var_dump($shipments); //debug
            echo '<br />'; //debug
            $param=array(
                'ClientCode'=>'AAAAA',
                'ProfileCode'=>'AAAAA',
                'ClientToken'=>$userToken,
                'DestCity'=>$_REQUEST['DestCity'],
                'DestCountry'=>$_REQUEST['DestCountry'],
                'DestState'=>$_REQUEST['DestState'],
                'DestZip'=>$_REQUEST['DestZip'],
                'isBatch'=>'false',
                'OrigCity'=>$_REQUEST['OrigCity'],
                'OrigCountry'=>$_REQUEST['OrigCountry'],
                'OrigState'=>$_REQUEST['OrigState'],
                'OrigZip'=>$_REQUEST['OrigZip'],
                'RequestId'=>$_REQUEST['RequestId'],
                'ShipmentDate'=>$_REQUEST['ShipmentDate'],
                'Shipments'=>$shipments,
                'srvToken'=>$this->srvtoken,
                'userToken'=>$userToken
            );

            echo 'Set rate request parameters to: <br />'; //debug
            print_r($param); //debug
            echo '<br />'; //debug
            $resp=$link->GetLTLRates($param);
            return($resp);
            break;
        case 'METHODS':
            $resp='';
            foreach($link->__getFunctions() as $key=>$value) {
                $resp.= ''
                . '<div style="width: 35px; background: yellow; float: left;">'.$key.'</div>'
                . '<div style="background: white; float: left;">'.$value.'</div>'
                . '<div style="clear: both; height: 0px;"></div>';
            }
            return($resp);
            break;
        default:
            return(false);
        }
    }
}



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
vacunita, the definition is listed within my original post or are you looking for something different?

Here it is again
Code:
<s:Envelope xmlns:s="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/">[/URL]
   <s:Body>
      <GetLTLRates xmlns="[URL unfurl="true"]http://tempuri.org/">[/URL]
         <ltlRequest xmlns:a="[URL unfurl="true"]http://schemas.datacontract.org/2004/07/LogisticsAppSuite.RatingEngine.DataModels"[/URL] xmlns:i="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">[/URL]
           <a:AccessorialCodes>
               <!--Zero or more repetitions:-->
               <a:string>IDC</a:string>
            </a:AccessorialCodes>
            <a:ClientCode>xxxxx</a:ClientCode>
            <a:DestCity>CANTON</a:DestCity>
            <a:DestCountry>US</a:DestCountry>
            <a:DestState>CT</a:DestState>
            <a:DestZip>06019</a:DestZip>
            <a:IsBatch>false</a:IsBatch>
            <a:Miles>0</a:Miles>
            <a:OrigCity>BRISTOL</a:OrigCity>
            <a:OrigCountry>US</a:OrigCountry>
            <a:OrigState>CT</a:OrigState>
            <a:OrigZip>06010</a:OrigZip>
            <a:ProfileCode>xxxxx</a:ProfileCode>
            <a:RequestId>5bd55929-94e4-4399-8986-2397f68a2583</a:RequestId>
            <a:Route i:nil="true"/>
            <a:SCAC i:nil="true"/>
            <a:ServiceLevelCode i:nil="true"/>
            <a:ShipmentDate>2014-07-08</a:ShipmentDate>
            <a:Shipments>
               <a:Shipment>
                  <a:Class>50</a:Class>
                  <a:HazMat>false</a:HazMat>
                  <a:Height i:nil="true"/>
                  <a:Length i:nil="true"/>
                  <a:NMFC i:nil="true"/>
                  <a:Pallets>1</a:Pallets>
                  <a:Pieces i:nil="true"/>
                  <a:Weight>1000</a:Weight>
                  <a:Width i:nil="true"/>
               </a:Shipment>
            </a:Shipments>
            <a:SrvToken>BBBBBB</a:SrvToken>
            <a:UsrToken>DDDDDD</a:UsrToken>
            <a:ZoneCode i:nil="true"/>
         </ltlRequest>
      </GetLTLRates>
   </s:Body>
</s:Envelope>

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
That's the data definition. What I was going for is the method used to send it. i.e $resp=$link->GetLTLRates($param);

Are you sure its expecting a single parameter as an array?

It may be expecting straight XML (unlikely, but possible), or something entirely different.


In any case, Does the the Fatal Error provide a line number?








----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Line 130, which would had been the line where the method is called

$resp=$link->GetLTLRates($param);

As per the use of array vs xml, notice that parameters are built as array on other calls such as Login() and it works.

I am adding alternative code to setup as xml just to make sure I eliminate all possible causes of the problem.

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
I changed the code to setup an alternative parameter as XML - here is the new parameter
Code:
<s:Envelope xmlns:s="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope[/URL]
/">
   <s:Body>
      <GetLTLRates xmlns="[URL unfurl="true"]http://tempuri.org/">[/URL]
         <ltlRequest xmlns:a="[URL unfurl="true"]http://aa-bb-ccc-ddd"[/URL] xmlns:i="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">[/URL]
           <a:AccessorialCodes>
               <a:string></a:string>
            </a:AccessorialCodes>
            <a:ClientCode>AAAA</a:ClientCode>
            <a:DestCity>SPRINGFIELD</a:DestCity>
            <a:DestCountry>USA</a:DestCountry>
            <a:DestState>MO</a:DestState>
            <a:DestZip>65804</a:DestZip>
            <a:IsBatch>false</a:IsBatch>
            <a:Miles>0</a:Miles>
            <a:OrigCity>BRIDGEHAMPTON</a:OrigCity>
            <a:OrigCountry>USA</a:OrigCountry>
            <a:OrigState>NY</a:OrigState>
            <a:OrigZip>11932</a:OrigZip>
            <a:ProfileCode>DDDD</a:ProfileCode>
            <a:RequestId>aaaa</a:RequestId>
            <a:Route i:nil="false"/>
            <a:SCAC i:nil="false"/>
            <a:ServiceLevelCode i:nil="false"/>
            <a:ShipmentDate>2015-12-18</a:ShipmentDate>
            <a:Shipments>
            <a:Shipment>
   <a:Class>50</a:Class>
   <a:HazMat>false</a:HazMat>
   <a:Height>50</a:Height>
   <a:Length>50</a:Length>
   <a:NMFC i:nil="true"/>
   <a:Pallets>50</a:Pallets>
   <a:Pieces>50</a:Pieces>
   <a:Weight>50</a:Weight>
   <a:Width i:nil="true"/>
</a:Shipment><a:Shipment>
   <a:Class>50</a:Class>
   <a:HazMat>false</a:HazMat>
   <a:Height>50</a:Height>
   <a:Length>50</a:Length>
   <a:NMFC i:nil="true"/>
   <a:Pallets>50</a:Pallets>
   <a:Pieces>50</a:Pieces>
   <a:Weight>50</a:Weight>
   <a:Width i:nil="true"/>
</a:Shipment>
            </a:Shipments>
            <a:SrvToken>dddd</a:SrvToken>
            <a:UsrToken>ddddd</a:UsrToken>
            <a:ZoneCode i:nil="true"/>
         </ltlRequest>
      </GetLTLRates>
   </s:Body>
</s:Envelope>


Here is the error as shown
Code:
<br />
Fatal error: Uncaught SoapFault exception: [a:InternalServiceFault] Object reference not set to an instance of an object. in /usr/lib/apache2/htdocs-dev/sclass/saas.php:168 Stack trace: #0 [internal function]: SoapClient->__call('GetLTLRates', Array) #1 /usr/lib/apache2/htdocs-dev/sclass/saas.php(168): SoapClient->GetLTLRates('<s:Envelope xml...') #2 /usr/lib/apache2/htdocs-dev/ajax/ajaxControl.php(72): SaaS->action('LTLRATE') #3 {main} thrown in /usr/lib/apache2/htdocs-dev/sclass/saas.php on line 168

since at the referenced line I am pointing to
$link->, here is the var_dump of it

Code:
object(SoapClient)#3 (3) {
  ["_soap_version"]=>
  int(1)
  ["sdl"]=>
  resource(6) of type (Unknown)
  ["httpurl"]=>
  resource(8) of type (Unknown)
}


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Something somewhere is expecting an object and is not getting one. It looks to be something related with the webservice interface.

The __getFunctions() method should your provide you with a list of methods available for that webservice, and their definitions.

If you look for GetLTLRates() what does it say about it?






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top