Link to home
Start Free TrialLog in
Avatar of namsu55
namsu55Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Trying alternative Soap Address if First Fails using standard PHP SOAP class

If I want to try another address if the first one fails, how would I go about doing this. I have exceptions in each of the web service functions I have wrapped. So if an error occurs that's related to the web service in terms of time out or not being found I would like to use the other address. I don't know how to go about this.
Avatar of Aaron Tomosky
Aaron Tomosky
Flag of United States of America image

If the call Stack can be written as a function that takes the soap address as input you could just call the function with address1 and on fail, call it again with address2
Avatar of namsu55

ASKER

How would I do that. So for example look at my code.

In the catch what would you expect me to do, call a private function, which uses __setLocation?

I'm not too sure can you give me an example.
public function addMember($memberArray){

		$this->debugObj->output("addMember function START");

		if (!is_array($memberArray)){

			return "This is not an array. You require an array of all the details of the member you would like to add";

		}

		$this->debugObj->output("addMember function - Trying to add member details - " . print_r($memberArray, true));

		try{

			$AddMemberResponse = $this->_DNX->addMemberMethod(array('Security' => $this->_securityDetails, 'Member' => $memberArray));

		}  catch(SoapFault $fault){

			return "Soap has an error. " . $fault;

		} catch(Exception $error){

			return $error;

		}

		$this->debugObj->output("addMember function - Response from addMemberMethod Web Service - " . print_r($AddMemberResponse, true));

		if($this->success($AddMemberResponse->Code)){

			$this->debugObj->output("addMember function - Successfully entered the member, response was a 1.");
			return true;

		} else {

			$errorCode = $this->error_codes($AddMemberResponse->Code);
			$this->debugObj->output("addMember function - Error code returned from web service, response was - " . $errorCode);
			return $errorCode;

		}

		$this->debugObj->output("addMember function END");

	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Aaron Tomosky
Aaron Tomosky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of namsu55

ASKER

Good idea I will try that from the constructor.