zend soap server response set custom ns1 namespace

心不动则不痛 提交于 2019-12-04 10:07:46
dskanth

Finally, i decided to parse the incoming SOAP request manually in my Controller:

// TestController.php
class TestSoapServer extends Zend_Soap_Server 
{
    // Handle the request and generate suitable response    
    public function handle($request = null)
    {
      if (null === $request) {    
       $request = file_get_contents('php://input');
      }
      // Parse request, generate a static/dynamic response and return it.

      // return parent::handle($request); // Actual response

    // Custom response
    $doc = new DOMDocument();
    libxml_use_internal_errors(true);
    $doc->loadHTML($request);
    libxml_clear_errors();
    $xml = $doc->saveXML($doc->documentElement);
    $xml = simplexml_load_string($xml);
    $int = $xml->body->envelope->body->getdouble->int;
    $value = $int * 2;

    $result = '<SOAP-ENV:Envelope 
               SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"             
               xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:ns1="http://example.com/public/test/test" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
               <SOAP-ENV:Body>
               <ns1:TestResult>';

     $result .= '<IntegerResult><Value>'.$value.'</Value></IntegerResult>';

    $result .= '</ns1:TestResult>
                </SOAP-ENV:Body>
                </SOAP-ENV:Envelope>';

    return $result;
    }
}
kingAm

I had similar requirements in my jax ws implementation. And surprisingly i found out,

Here

Similarly i don't think zend framework gives you control over message name. Read zend specification for confirmation.

Only option you have is to parse response as per your requirement after receiving at client side using DOM or Xpath. I am not familiar with zend framework so can't give u working code right now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!