• Модуль: webservice
  • Путь к файлу: ~/bitrix/modules/webservice/classes/general/soap/soapresponse.php
  • Класс: forCSOAPResponse
  • Вызов: CSOAPResponse::payload
function payload( )
{
	$root = new CXMLCreator("soap:Envelope");
	$root->setAttribute("xmlns:soap", BX_SOAP_ENV);

	// add the body
	$body = new CXMLCreator( "soap:Body" );

	// Check if it's a fault
	if (is_object($this->Value) && ToUpper(get_class($this->Value)) == 'CSOAPFAULT')
	{
		$fault = new CXMLCreator( "soap:Fault" );

		$faultCodeNode = new CXMLCreator( "faultcode" );
		$faultCodeNode->setData($this->Value->faultCode());

		$fault->addChild( $faultCodeNode );

		$faultStringNode = new CXMLCreator( "faultstring" );
		$faultStringNode->setData( $this->Value->faultString() );

		$fault->addChild( $faultStringNode );
		
		if ($this->Value->detail)
			$fault->addChild($this->Value->detail());

		$body->addChild( $fault );
	}
	else
	{
		// add the request
		$responseName = $this->Name . "Response";
		$response = new CXMLCreator( $responseName );
		$response->setAttribute("xmlns", $this->Namespace);
		if (!isset($this->typensVars[$this->Name]["output"]) or !count($this->typensVars[$this->Name]["output"]))
		{
			if (count($this->typensVars))
			{
				$GLOBALS['APPLICATION']->ThrowException("payload() can't find output type declaration.", "SoapRespnose::payload()");
				return;
			}
			else
			{
				//print_r($this->Value);
				//die();
				// EncodeLight
				$value = CXMLCreator::encodeValueLight( $this->ValueName, $this->Value );
			}

			$response->addChild( $value );
		}
		else
		{
			//$return = new CXMLCreator($returnType);
			$valueEncoder = new CSOAPCodec();
			$valueEncoder->setTypensVars($this->typensVars);

			foreach ($this->typensVars[$this->Name]["output"] as $returnType => $returnParam)
			{
				if (!$returnType)
				{
					$GLOBALS['APPLICATION']->ThrowException("payload() can't find output type declaration for {$this->Name}.", "SoapRespnose::payload()");
					return;
				}

				$valueEncoder->setOutputVars($this->Name);

				$value = $valueEncoder->encodeValue($returnType, isset($this->Value[$returnType]) ? $this->Value[$returnType] : $this->Value);

				$response->addChild($value);
			}

			//AddM
		}


		$body->addChild( $response );
	}

	$root->addChild( $body );

	//AddMessage2Log($root->getXML());
	return CXMLCreator::getXMLHeader().$root->getXML();
}