Jump to content

[SOLVED] Dealing with SOAP results


tndono

Recommended Posts

I've been having some fun. But I've gotten myself into a pickle. I was curious if anyone could help me out, please?

 

I'm playing with a SOAP call to a web service that's not very well documented. It's taken me a couple of days to work out syntax and formatting, with little help from the web service provider.

 

I can provide the code in its entirety. It is at the bottom of this post. The web service does not require a license key.

 

My question is, how do I break out the result from the SOAP call into it's constituent elements to do further processing. I believe the result is a multidimensional array, as I can output the result using a print_r function. However, I can't figure out how to call the various elements of the array. Below is the output.

 

Thanks,

 

Tim

 

Lookup by Address only:

Array ( [0] => stdClass Object ( [intReturnCode] => 0 [strReturnShortDesc] => Address Found(City=MEDICINE LODGERslt=S5HPNTSCZA,Stat=10,-98.5870256x37.2779374) [strConfirmationNum] => 116409 [strEventTimeStamp] => 05/18/2007 14:21:15 [FIPSRecordList] => Array ( [0] => stdClass Object ( [intState] => 20 [strJurisdictionType] => STA [strCompositeSER] => MEDBA [intJurisdictionFIPS] => 20 [strGeneralTaxRateIntrastate] => 5.3 [strGeneralTaxRateInterstate] => 5.3 [strFoodDrugTaxRateIntrastate] => 5.3 [strFoodDrugTaxRateInterstate] => 5.3 ) [1] => stdClass Object ( [intState] => 20 [strJurisdictionType] => CTY [strCompositeSER] => MEDBA [intJurisdictionFIPS] => 7 [strGeneralTaxRateIntrastate] => 1 [strGeneralTaxRateInterstate] => 1 [strFoodDrugTaxRateIntrastate] => 1 [strFoodDrugTaxRateInterstate] => 1 ) [2] => stdClass Object ( [intState] => 20 [strJurisdictionType] => CIT [strCompositeSER] => MEDBA [intJurisdictionFIPS] => 45500 [strGeneralTaxRateIntrastate] => 0.75 [strGeneralTaxRateInterstate] => 0.75 [strFoodDrugTaxRateIntrastate] => 0.75 [strFoodDrugTaxRateInterstate] => 0.75 ) ) ) )

 

$ansa is an array: 1

 

 

And the code that generated the result follows:

 

<?php

 

$wskdor = "http://services.taxwatch.biz/rates/kansas/sstp.wsdl";

$client = new SoapClient($wskdor,array('trace' => 1));

 

  $zip = 67104;

  $pluszip = 0000;

  $reqdate = "2007-05-17";

  $address = "313 S. Iliff";

  $addnum = "313";

  $addst = "Iliff";

  $adddir = Null;

  $addpredir = "S";

  $addstsuf = Null;

  $city = "Medicine Lodge";

  $state = "kansas";

  $stateabbr = "ks";

 

 

// Call the GetFIPSByAddress method

$ansa = array ($client->GetFIPSByAddress($addnum,$addpredir,$addst,$addstsuf,$adddir,$city,$zip,$pluszip,$reqdate));

 

print "<p>";

echo "<p>Lookup by Address only: <br>";

print_r($ansa);

 

$yes = is_array($ansa);

print "<p>\$ansa is an array: " . $yes;

 

?>

Link to comment
Share on other sites

Being extremely new to php, not sure what you meant, but, I did this.

 

echo $client->GetFIPSByAddress($addnum,$addpredir,$addst,$addstsuf,$adddir,$city,$zip,$pluszip,$reqdate);

 

and got the following, where line 34 was the above line.

 

Catchable fatal error: Object of class stdClass could not be converted to string in C:\Apache2\htdocs\kdor1.php on line 34

Link to comment
Share on other sites

Or, doing this.

 

$ansa = $client->GetFIPSByAddress($addnum,$addpredir,$addst,$addstsuf,$adddir,$city,$zip,$pluszip,$reqdate);

print_r( $ansa);

 

produced the following results.

 

stdClass Object ( [intReturnCode] => 0 [strReturnShortDesc] => Address Found(City=MEDICINE LODGERslt=S5HPNTSCZA,Stat=10,-98.5870256x37.2779374) [strConfirmationNum] => 116421 [strEventTimeStamp] => 05/18/2007 14:48:11 [FIPSRecordList] => Array ( [0] => stdClass Object ( [intState] => 20 [strJurisdictionType] => STA [strCompositeSER] => MEDBA [intJurisdictionFIPS] => 20 [strGeneralTaxRateIntrastate] => 5.3 [strGeneralTaxRateInterstate] => 5.3 [strFoodDrugTaxRateIntrastate] => 5.3 [strFoodDrugTaxRateInterstate] => 5.3 ) [1] => stdClass Object ( [intState] => 20 [strJurisdictionType] => CTY [strCompositeSER] => MEDBA [intJurisdictionFIPS] => 7 [strGeneralTaxRateIntrastate] => 1 [strGeneralTaxRateInterstate] => 1 [strFoodDrugTaxRateIntrastate] => 1 [strFoodDrugTaxRateInterstate] => 1 ) [2] => stdClass Object ( [intState] => 20 [strJurisdictionType] => CIT [strCompositeSER] => MEDBA [intJurisdictionFIPS] => 45500 [strGeneralTaxRateIntrastate] => 0.75 [strGeneralTaxRateInterstate] => 0.75 [strFoodDrugTaxRateIntrastate] => 0.75 [strFoodDrugTaxRateInterstate] => 0.75 ) ) )

Link to comment
Share on other sites

you're calling a function, not echoing out a value in an object...

 

$result = GetFIPSByAddress($addnum,$addpredir,$addst,$addstsuf,$adddir,$city,$zip,$pluszip,$reqdate);

foreach ($result->FIPSRecordList as $record) {
  foreach ($record as $key => $value) {
    echo $key . " = " . $value . "<br />";
  }
}

 

I think that should loop through them...

Link to comment
Share on other sites

Most excellent. I had to make one small change to the first line, adding the instantiated SoapClient before the GetFPISByAddress method. Other than that, it works great. Thanks a bunch hitman6003, Oh Guru.

 

$result = $client->GetFIPSByAddress($addnum,$addpredir,$addst,$addstsuf,$adddir,$city,$zip,$pluszip,$reqdate);

 

foreach ($result->FIPSRecordList as $record) {

  foreach ($record as $key => $value) {

    echo $key . " = " . $value . "<br />";

  }

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.