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

Posted on 2011-04-18
Last Modified: 2012-05-11
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.
Question by:namsu55
    LVL 38

    Expert Comment

    by:Aaron Tomosky
    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

    Author Comment

    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));
    			$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));
    			$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

    LVL 38

    Accepted Solution

    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.

    Author Comment

    Good idea I will try that from the constructor.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now