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.
namsu55Asked:
Who is Participating?
 
Aaron TomoskySD-WAN SimplifiedCommented:
I think you should look for a simple soap function that will return info or anything that you don't have to pass anything to. Like a version check or something. It will let you test connectivity. put that in your code before you call this addMember(). If it fails, change the address and try again. Then if success call this function.
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
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
0
 
namsu55Author Commented:
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

0
 
namsu55Author Commented:
Good idea I will try that from the constructor.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.