public function callMethod($name, $httpMethod = "POST", $params = array(), $payload = null, $returnClass = null, $expectedExceptions = null) {

        $objectToFormatConverter = $this->dataFormat == self::DATA_FORMAT_JSON ? new ObjectToJSONConverter() : new ObjectToXMLConverter();
        $formatToObjectConverter = $this->dataFormat == self::DATA_FORMAT_JSON ? new JSONToObjectConverter() : new XMLToObjectConverter();


        if (!is_array($expectedExceptions)) {
            $expectedExceptions = array();
        }

        if (!ArrayUtils::isAssociative($expectedExceptions)) {
            $expectedExceptions = array_combine($expectedExceptions, $expectedExceptions);
        }

        $parameters = $this->globalParameters;
        if (is_array($parameters) && is_array($params)) {
            $parameters = array_merge($parameters, $params);
        }

        foreach ($parameters as $key => $value) {
            $parameters[$key] = $value;
        }

        if ($payload) {
            $payload = $objectToFormatConverter->convert($payload);
        }

        $request = new HttpRemoteRequest($this->webServiceURL . "/" . $name, $httpMethod, $parameters, $payload);

        try {
            $result = $request->dispatch();

            if ($this->dataFormat == self::DATA_FORMAT_JSON) {
                $result = $formatToObjectConverter->convert($result);
            }


            if ($returnClass) {
                $result = SerialisableArrayUtils::convertArrayToSerialisableObjects($result, $returnClass);
            }

            return $result;

        } catch (HttpRequestErrorException $e) {

            $response = $e->getResponse();
            
            if ($this->dataFormat == self::DATA_FORMAT_JSON) {
                $response = $formatToObjectConverter->convert($response);


                if ($response["exceptionClass"] && isset($expectedExceptions[$response["exceptionClass"]])) {
                    $response = SerialisableArrayUtils::convertArrayToSerialisableObjects($response, $expectedExceptions[$response["exceptionClass"]]);
                }

            }

            if ($response instanceof SerialisableException) {
                throw $response;
            } else {
                throw $e;
            }

        }


    }
public function callMethod($name, $httpMethod = "POST", $params = array(), $payload = null, $returnClass = null, $expectedExceptions = null) {

        $objectToFormatConverter = $this->dataFormat == self::DATA_FORMAT_JSON ? new ObjectToJSONConverter() : new ObjectToXMLConverter();
        $formatToObjectConverter = $this->dataFormat == self::DATA_FORMAT_JSON ? new JSONToObjectConverter() : new XMLToObjectConverter();


        if (!is_array($expectedExceptions)) {
            $expectedExceptions = array();
        }

        if (!ArrayUtils::isAssociative($expectedExceptions)) {
            $expectedExceptions = array_combine($expectedExceptions, $expectedExceptions);
        }

        $parameters = $this->globalParameters;
        if (is_array($parameters) && is_array($params)) {
            $parameters = array_merge($parameters, $params);
        }

        foreach ($parameters as $key => $value) {
            $parameters[$key] = $value;
        }

        if ($payload) {
            $payload = $objectToFormatConverter->convert($payload);
        }

        $request = new HttpRemoteRequest($this->webServiceURL . "/" . $name, $httpMethod, $parameters, $payload);

        try {
            $result = $request->dispatch();

            if ($this->dataFormat == self::DATA_FORMAT_JSON) {
                $result = $formatToObjectConverter->convert($result);
            }


            if ($returnClass) {
                $result = SerialisableArrayUtils::convertArrayToSerialisableObjects($result, $returnClass);
            }

            return $result;

        } catch (HttpRequestErrorException $e) {

            $response = $e->getResponse();
            
            if ($this->dataFormat == self::DATA_FORMAT_JSON) {
                $response = $formatToObjectConverter->convert($response);


                if ($response["exceptionClass"] && isset($expectedExceptions[$response["exceptionClass"]])) {
                    $response = SerialisableArrayUtils::convertArrayToSerialisableObjects($response, $expectedExceptions[$response["exceptionClass"]]);
                }

            }

            if ($response instanceof SerialisableException) {
                throw $response;
            } else {
                throw $e;
            }

        }


    }
public function callMethod ( $ name , $ httpMethod = "POST" , $ params = array ( ) , $ payload = null , $ returnClass = null , $ expectedExceptions = null ) { $ objectToFormatConverter = $ this -> dataFormat == self :: DATA_FORMAT_JSON ? new ObjectToJSONConverter ( ) : new ObjectToXMLConverter ( ) ; $ formatToObjectConverter = $ this -> dataFormat == self :: DATA_FORMAT_JSON ? new JSONToObjectConverter ( ) : new XMLToObjectConverter ( ) ; if ( ! is_array ( $ expectedExceptions ) ) { $ expectedExceptions = array ( ) ; } if ( ! ArrayUtils :: isAssociative ( $ expectedExceptions ) ) { $ expectedExceptions = array_combine ( $ expectedExceptions , $ expectedExceptions ) ; } $ parameters = $ this -> globalParameters ; if ( is_array ( $ parameters ) && is_array ( $ params ) ) { $ parameters = array_merge ( $ parameters , $ params ) ; } foreach ( $ parameters as $ key => $ value ) { $ parameters [ $ key ] = $ value ; } if ( $ payload ) { $ payload = $ objectToFormatConverter -> convert ( $ payload ) ; } $ request = new HttpRemoteRequest ( $ this -> webServiceURL . "/" . $ name , $ httpMethod , $ parameters , $ payload ) ; try { $ result = $ request -> dispatch ( ) ; if ( $ this -> dataFormat == self :: DATA_FORMAT_JSON ) { $ result = $ formatToObjectConverter -> convert ( $ result ) ; } if ( $ returnClass ) { $ result = SerialisableArrayUtils :: convertArrayToSerialisableObjects ( $ result , $ returnClass ) ; } return $ result ; } catch ( HttpRequestErrorException $ e ) { $ response = $ e -> getResponse ( ) ; if ( $ this -> dataFormat == self :: DATA_FORMAT_JSON ) { $ response = $ formatToObjectConverter -> convert ( $ response ) ; if ( $ response [ "exceptionClass" ] && isset ( $ expectedExceptions [ $ response [ "exceptionClass" ] ] ) ) { $ response = SerialisableArrayUtils :: convertArrayToSerialisableObjects ( $ response , $ expectedExceptions [ $ response [ "exceptionClass" ] ] ) ; } } if ( $ response instanceof SerialisableException ) { throw $ response ; } else { throw $ e ; } } }
Implement the call method to call a proxy service

@param string $name
@param $httpMethod
@param array $params
@param mixed $payload
@param string $returnClass
@param array $expectedExceptions an array of expected exceptions.  This can simply be a values array of class names or an associative array defining mappings to client classes.
Implement the call method to call a proxy service