WCF Service

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Architek
Forum Commoner
Posts: 44
Joined: Wed Jul 01, 2009 5:01 am
Location: Portland OR

WCF Service

Post by Architek »

Hello,

I am hoping someone can hold my hand through this... I have had not experience with web services calls until a recent project has required it.
I spent probably a good 6 hours going through the php.net documentation site for the SoapClient::__soapCall function but all the examples I have tried from that have not worked out..

I have also looked here and this thread is pretty much my exact question but the response from someone is to go look at the php.net site.
viewtopic.php?f=1&t=106716&p=568888&hilit=wcf#p568888

here is the email section where the developer sent me the quick info on the service... Not sure if those are named parameters or if they are just place holder examples????

The method you will call GetSPSOrderData(this.txtOrderNumber.Text,string.Empty,
string.Empty,string.Empty) which will return an array of key/value pairs.
I unfortunatly best learn from a problem I have and someone showing me where I might be going wrong as apposed to trying to interperet someone elses code structure to my own.

I essentially need to call this service and parse the value from the keys

right now it is returning empty values in the var_dump so I dont know if I am sending th call correctly.

I also dont know how to handle the error at the end of the output and what process I would take to parse the value from each key once it is returned succesfully.

Here is the php client call

Code: Select all

<?php

header('Content-Type: text/plain');
$ordernumber = "XAT10000119";

try
{ 
	$client = new SoapClient("http://someserver.domain.local/eReetWCFService/eReetService.svc?wsdl");          
 
   echo("<br />Dumping client object:<br />");
   var_dump($client);
   echo("<br /><br />");
   
   echo("Dumping client functions:<br />");
   var_dump($client->__getFunctions());
   echo("<br /><br />");
   
   $parameters = array("this.txtOrderNumber.Text" => $ordernumber, "string.Empty" => "", "string.Empty" => "", "string.Empty" => "");
   echo("Calling SOAP function with params $ordernumber<br /><br />");
   $objresult = $client->GetSPSOrderData($parameters); 
   
   if( is_soap_fault($objresult) == true )
   {
      echo "There was an error.<br /><br />";
   }
   else
   {
	 var_dump($objresult);
	  $simpleresult = $objresult->GetSPSOrderDataResult;
	  echo("Result: ". $simpleresult."<br /><br />");
   }
}
catch(Exception $e)
{
   echo "Exception: ".  $e->getMessage(). "\n";
}
 
?>

Here is the output....
Dumping client object:
object(SoapClient)#1 (2) { ["_soap_version"]=> int(1) ["sdl"]=> resource(12) of type (Unknown) }

Dumping client functions:
array(1) { [0]=> string(68) "GetSPSOrderDataResponse GetSPSOrderData(GetSPSOrderData $parameters)" }

Calling SOAP Add function with params XAT10000119

object(stdClass)#2 (1) { ["GetSPSOrderDataResult"]=> object(stdClass)#3 (1) { ["KeyValueOfstringstring"]=> array(102) { [0]=> object(stdClass)#4 (2) { ["Key"]=> string(38) "order.Buyer[0].CurrentAddress1Address2" ["Value"]=> string(0) "" } [1]=> object(stdClass)#5 (2) { ["Key"]=> string(26) "order.Buyer[0].CurrentCity" ["Value"]=> string(0) "" } [2]=> object(stdClass)#6 (2) { ["Key"]=> string(34) "order.Buyer[0].CurrentCityStateZip" ["Value"]=> string(0) "" } [3]=> object(stdClass)#7 (2) { ["Key"]=> string(27) "order.Buyer[0].CurrentPhone" ["Value"]=>

---- Lots more here ---

" ["Value"]=> string(0) "" } [97]=> object(stdClass)#101 (2) { ["Key"]=> string(29) "order.Seller[0].ForwardingZip" ["Value"]=> string(0) "" } [98]=> object(stdClass)#102 (2) { ["Key"]=> string(30) "order.Seller[0].Person[0].Name" ["Value"]=> string(0) "" } [99]=> object(stdClass)#103 (2) { ["Key"]=> string(30) "order.SellerAllNamesWithCommas" ["Value"]=> string(0) "" } [100]=> object(stdClass)#104 (2) { ["Key"]=> string(45) "order.SettlementAgent[0].Person[0].LookupCode" ["Value"]=> string(0) "" } [101]=> object(stdClass)#105 (2) { ["Key"]=> string(39) "order.SettlementAgent[0].Person[0].Name" ["Value"]=> string(0) "" } } } }


Catchable fatal error: Object of class stdClass could not be converted to string in C:\Inetpub\wwwroot\ereet\ereet-form-mobilehome.php on line 106
Any help would be great otherwise a whole lot of trial and error.

Thanks Much!
User avatar
Architek
Forum Commoner
Posts: 44
Joined: Wed Jul 01, 2009 5:01 am
Location: Portland OR

Re: WCF Service

Post by Architek »

okay I feel kind of like I am making progress... I have it parsing each child object section from an embeded array that was returned...

result now looks like follows.

I looked at the output and once I formatted it with a <pre> tag I saw the logical structure to walk it via an object property selector and then once I got to the embeded array switch to the index method and once passing that wall call each indexed item with another object property on the KEY and VALUE variables.

geezzz..

is this an issue with the way the web service is published or is this just "How it is"?

Something I could be doing easier since I am so new at it?

This was the output that made the lightbulb turn on for me...

Code: Select all


// stdClass Object
// (
    // [0] => stdClass Object
        // (
            // [GetSPSOrderDataResult] => stdClass Object
                // (
                    // [KeyValueOfstringstring] => Array
                        // (
                            // [0] => stdClass Object
                                // (
	                   //[Key] => order.Buyer[0].CurrentAddress1Address2 [Value] => )
I guess I was hoping to be able to call each item based on the elements friendly name such as order.buyer...

anyone have any input as to what you might do to handle parsing this out.

Use a foreach statement some how with a if Key == Then???
User avatar
Architek
Forum Commoner
Posts: 44
Joined: Wed Jul 01, 2009 5:01 am
Location: Portland OR

Re: WCF Service

Post by Architek »

I am giving up for a while...

here is my current code structure... kind of sucky and I am not satisfied considering I am not sure how to call the values via their key names.

Code: Select all

$ordernumber = "XAT10000109";

try
	{ 
		$client = new SoapClient("http://someserver.domain.local/eReetWCFService/eReetService.svc?wsdl");      
		$parameters = array("this.txtOrderNumber.Text" => $ordernumber, "string.Empty" => "", "string.Empty" => "", "string.Empty" => "");
		$objresult = $client->GetSPSOrderData($parameters);
		if(is_soap_fault($objresult) == true)
		{
		  echo "There was an error.<br /><br />";
		}
		else
		{
		$objresult = $objresult->GetSPSOrderDataResult;
		$objresult = $objresult->KeyValueOfstringstring;
		$objresult = $objresult[5];
		$fieldkey = $objresult->Key;
		echo "<br />FIELD KEY :".$fieldkey;
		$fieldvalue = $objresult->Value;
		echo "<br />FIELD VALUE :".$fieldvalue;
		
		$objresult = $client->GetSPSOrderData($parameters); 
		$objresult = $objresult->GetSPSOrderDataResult;
		$objresult = $objresult->KeyValueOfstringstring;
		$objresult = $objresult[76];
		$fieldkey = $objresult->Key;
		echo "<br />FIELD KEY :".$fieldkey;
		$fieldvalue = $objresult->Value;
		echo "<br />FIELD VALUE :".$fieldvalue;
	
	   }
	}
catch(Exception $e)
{
   echo "Exception: ".$e->getMessage()."\n";
}
If anyone has some input on how I can grab it with out using

the following in each field on my form that I want to populate by defining the actual index position wich could change when new items are added or removed from the service.

Code: Select all

                                $objresult = $objresult->GetSPSOrderDataResult;
		$objresult = $objresult->KeyValueOfstringstring;
		$objresult = $objresult[5]; //Buyers Zip Code
		$fieldvalue = $objresult->Value;
		if($fieldvalue > ""){echo "value=\"".$fieldvalue."\"";}
Thanks,
Shane Saviers!
User avatar
Architek
Forum Commoner
Posts: 44
Joined: Wed Jul 01, 2009 5:01 am
Location: Portland OR

Re: WCF Service - Parsing Array/Objects???

Post by Architek »

I think I have come down to this if I am stuck with the current webservice output...

I was thinking I could do a foreach statement here on the object result giving me the following output that I need to parse and create into my own array so I can retrieve properties via the associated name.

Code: Select all

stdClass Object ( 
	[Key] => order.Buyer[0].CurrentAddress1Address2 
	[Value] => 											) 

Here is the my current array to parse each returned object of the array... I dont want to have to maintain this for the existing 100+ items that I need to retrieve... I also am afraid of what kind of work I would need to do if the webservice changed.

there is a string replace in there to take out periods and brackets as shown above in the "Key" Value... (Hoping I can have them strip those on their side when creating this method...

Code: Select all

$objresult = $objresult->KeyValueOfstringstring; 
         $keystrip = array(".", "[", "]");
         $arrayresult[str_replace($keystrip, "", $objresult[0]->Key)] = $objresult[0]->Value;
         $arrayresult[str_replace($keystrip, "", $objresult[1]->Key)] = $objresult[1]->Value;
         $arrayresult[str_replace($keystrip, "", $objresult[2]->Key)] = $objresult[2]->Value;
         $arrayresult[str_replace($keystrip, "", $objresult[3]->Key)] = $objresult[3]->Value;
         $arrayresult[str_replace($keystrip, "", $objresult[4]->Key)] = $objresult[4]->Value;
My ultimate usage is going to be...

Code: Select all

<input type="text" <?php if($arrayresult["orderBuyer0CurrentState"] > ""){echo "value=\"".$arrayresult["orderBuyer0CurrentState"]."\" disabled=\"disabled\" class=\"field-disabled\"";} ?>></input>
Input would be greatly appreciated cause I am struggling as I make my way through this.


thx.
SS
User avatar
Architek
Forum Commoner
Posts: 44
Joined: Wed Jul 01, 2009 5:01 am
Location: Portland OR

Re: WCF Service

Post by Architek »

still looking to see if someone can help with breaking out a for each type method on the $arrayresult set.

also to note... I was returing no values on my query... I added a __getLastRequest() to my statement to see what I was passing and noticed that the required paramater was not making it into the xml string being sent.

I had to request they the developer let me know wha the variable name was and I defined it in an an array format and poof... out comes my values...

so my paramaters line from below now looks like this...

Code: Select all

$parameters = array("strOrderNumber" => $ordernumber,"","","");
Post Reply