function nusoapclient::call in Salesforce Suite 5.2
Same name and namespace in other branches
- 5 includes/nusoap.php \nusoapclient::call()
* calls method, returns PHP native type * *
Parameters
string $method SOAP server URL or path: * @param mixed $params An array, associative or simple, of the parameters * for the method call, or a string that is the XML * for the call. For rpc style, this call will * wrap the XML in a tag named after the method, as * well as the SOAP Envelope and Body. For document * style, this will only wrap with the Envelope and Body. * IMPORTANT: when using an array with document style, * in which case there * is really one parameter, the root of the fragment * used in the call, which encloses what programmers * normally think of parameters. A parameter array * *must* include the wrapper. * @param string $namespace optional method namespace (WSDL can override) * @param string $soapAction optional SOAPAction value (WSDL can override) * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers * @param boolean $rpcParams optional (no longer used) * @param string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override) * @param string $use optional (encoded|literal) the use when serializing parameters (WSDL can override) * @return mixed response from SOAP call * @access public
File
- includes/
nusoap.php, line 6569
Class
- nusoapclient
- nusoapclient higher level class for easy usage.
Code
function call($operation, $params = [], $namespace = 'http://tempuri.org', $soapAction = '', $headers = false, $rpcParams = null, $style = 'rpc', $use = 'encoded') {
$this->operation = $operation;
$this->fault = false;
$this
->setError('');
$this->request = '';
$this->response = '';
$this->responseData = '';
$this->faultstring = '';
$this->faultcode = '';
$this->opData = array();
$this
->debug("call: operation={$operation}, namespace={$namespace}, soapAction={$soapAction}, rpcParams={$rpcParams}, style={$style}, use={$use}, endpointType={$this->endpointType}");
$this
->appendDebug('params=' . $this
->varDump($params));
$this
->appendDebug('headers=' . $this
->varDump($headers));
if ($headers) {
$this->requestHeaders = $headers;
}
// serialize parameters
if ($this->endpointType == 'wsdl' && ($opData = $this
->getOperationData($operation))) {
// use WSDL for operation
$this->opData = $opData;
$this
->debug("found operation");
$this
->appendDebug('opData=' . $this
->varDump($opData));
if (isset($opData['soapAction'])) {
$soapAction = $opData['soapAction'];
}
if (!$this->forceEndpoint) {
$this->endpoint = $opData['endpoint'];
}
else {
$this->endpoint = $this->forceEndpoint;
}
$namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace;
$style = $opData['style'];
$use = $opData['input']['use'];
// add ns to ns array
if ($namespace != '' && !isset($this->wsdl->namespaces[$namespace])) {
$nsPrefix = 'ns' . rand(1000, 9999);
$this->wsdl->namespaces[$nsPrefix] = $namespace;
}
$nsPrefix = $this->wsdl
->getPrefixFromNamespace($namespace);
// serialize payload
if (is_string($params)) {
$this
->debug("serializing param string for WSDL operation {$operation}");
$payload = $params;
}
elseif (is_array($params)) {
$this
->debug("serializing param array for WSDL operation {$operation}");
$payload = $this->wsdl
->serializeRPCParameters($operation, 'input', $params);
}
else {
$this
->debug('params must be array or string');
$this
->setError('params must be array or string');
return false;
}
$usedNamespaces = $this->wsdl->usedNamespaces;
if (isset($opData['input']['encodingStyle'])) {
$encodingStyle = $opData['input']['encodingStyle'];
}
else {
$encodingStyle = '';
}
$this
->appendDebug($this->wsdl
->getDebug());
$this->wsdl
->clearDebug();
if ($errstr = $this->wsdl
->getError()) {
$this
->debug('got wsdl error: ' . $errstr);
$this
->setError('wsdl error: ' . $errstr);
return false;
}
}
elseif ($this->endpointType == 'wsdl') {
// operation not in WSDL
$this
->appendDebug($this->wsdl
->getDebug());
$this->wsdl
->clearDebug();
$this
->setError('operation ' . $operation . ' not present.');
$this
->debug("operation '{$operation}' not present.");
return false;
}
else {
// no WSDL
//$this->namespaces['ns1'] = $namespace;
$nsPrefix = 'ns' . rand(1000, 9999);
// serialize
$payload = '';
if (is_string($params)) {
$this
->debug("serializing param string for operation {$operation}");
$payload = $params;
}
elseif (is_array($params)) {
$this
->debug("serializing param array for operation {$operation}");
foreach ($params as $k => $v) {
$payload .= $this
->serialize_val($v, $k, false, false, false, false, $use);
}
}
else {
$this
->debug('params must be array or string');
$this
->setError('params must be array or string');
return false;
}
$usedNamespaces = array();
if ($use == 'encoded') {
$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
}
else {
$encodingStyle = '';
}
}
// wrap RPC calls with method element
if ($style == 'rpc') {
if ($use == 'literal') {
$this
->debug("wrapping RPC request with literal method element");
if ($namespace) {
$payload = "<{$operation} xmlns=\"{$namespace}\">" . $payload . "</{$operation}>";
}
else {
$payload = "<{$operation}>" . $payload . "</{$operation}>";
}
}
else {
$this
->debug("wrapping RPC request with encoded method element");
if ($namespace) {
$payload = "<{$nsPrefix}:{$operation} xmlns:{$nsPrefix}=\"{$namespace}\">" . $payload . "</{$nsPrefix}:{$operation}>";
}
else {
$payload = "<{$operation}>" . $payload . "</{$operation}>";
}
}
}
// serialize envelope
$soapmsg = $this
->serializeEnvelope($payload, $this->requestHeaders, $usedNamespaces, $style, $use, $encodingStyle);
$this
->debug("endpoint={$this->endpoint}, soapAction={$soapAction}, namespace={$namespace}, style={$style}, use={$use}, encodingStyle={$encodingStyle}");
$this
->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000));
// send
$return = $this
->send($this
->getHTTPBody($soapmsg), $soapAction, $this->timeout, $this->response_timeout);
if ($errstr = $this
->getError()) {
$this
->debug('Error: ' . $errstr);
return false;
}
else {
$this->return = $return;
$this
->debug('sent message successfully and got a(n) ' . gettype($return));
$this
->appendDebug('return=' . $this
->varDump($return));
// fault?
if (is_array($return) && isset($return['faultcode'])) {
$this
->debug('got fault');
$this
->setError($return['faultcode'] . ': ' . $return['faultstring']);
$this->fault = true;
foreach ($return as $k => $v) {
$this->{$k} = $v;
$this
->debug("{$k} = {$v}<br>");
}
return $return;
}
elseif ($style == 'document') {
// NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
// we are only going to return the first part here...sorry about that
return $return;
}
else {
// array of return values
if (is_array($return)) {
// multiple 'out' parameters, which we return wrapped up
// in the array
if (sizeof($return) > 1) {
return $return;
}
// single 'out' parameter (normally the return value)
$return = array_shift($return);
$this
->debug('return shifted value: ');
$this
->appendDebug($this
->varDump($return));
return $return;
// nothing returned (ie, echoVoid)
}
else {
return "";
}
}
}
}