数组中的肥皂响应

时间:2013-06-20 09:24:32

标签: php zend-framework soap

我想在php中获取soap响应。它不断作为一个对象进入我的Web浏览器,但不是作为xml。 WSDL显示为XML,但不显示收到的响应。下面是我的服务器端代码。肥皂服务器是Zend Soap

    ini_set("soap.wsdl_cache_enabled", 0);
    if (isset($_GET['wsdl'])){
        $wsdl = 'http://localhost/webservice/soap';

        $autoDiscover = new AutoDiscover();
        $autoDiscover->setOperationBodyStyle(
                array('use' => 'literal',
                        'namespace' => 'http://localhost/webservice/soap')
        );


        $autoDiscover->setBindingStyle(
                array('style' => 'rpc',
                        'transport' => 'http://schemas.xmlsoap.org/soap/http')
        );

        $autoDiscover->setComplexTypeStrategy(new ArrayOfTypeComplex());

        // $service is the class that does the handling of functions 
        $autoDiscover->setClass($service);
        $autoDiscover->setUri($wsdl);

       $response->getHeaders()->addHeaderLine('Content-Type', 'text/xml');

        $response->setContent($autoDiscover->toXml());

        } else {

            $server = new Server('http://localhost/webservice/soap?wsdl' 
            );
              // $service is the class that does the handling of functions 
            $server->setObject($service);
            $response->setContent($server->handle());

            }

            return $response;
           }

服务类

 class service
  {
 /**
 * 
 * @param string $Email
 * @return int $Credit
 */

public function checkCredits($Email)

{
    $validator = new email();

    if (!$validator->isValid($Email))
    {

        return new \SoapFault('5', 'Please Provide an Email');


    }
    $rowset = $this->tableGateway->select(array('EMAIL'=>$Email))

    $row = $rowset->current();
    $credits = $row->CREDITS;
    return $credits;
}

  }

请求是:

 try{
 $sClient = new SoapClient('http://localhost/webservice/soap?wsdl');
  $params = "email";
  $response = $sClient->checkCredits($params);
 var_dump($response);
 } catch(SoapFault $e){

var_dump($e);
}

2 个答案:

答案 0 :(得分:0)

这是我如何用SoapClient处理函数的一个例子:

$client = new SoapClient('http://url/Service.svc?wsdl');
$var = array('arg' => 10,
            'VA' => 48);
$varresponse = $client->Function($var);
print_r( $varresponse->FunctionResult);

希望这会帮助你。

答案 1 :(得分:0)

你的soapserver应该看起来像这样:

<?php
if(!extension_loaded("soap")){
  dl("php_soap.dll");
}

    ini_set("soap.wsdl_cache_enabled","0");
    $server = new SoapServer("hello.wsdl");

    function doHello($yourName){
      return "Hello, ".$yourName;
    }

    $server->AddFunction("doHello");
    $server->handle();

?>

你是如何建立自己的?你还有什么东西吗?

现在,您的客户应该是这样的:

<?php

try{
  $sClient = new SoapClient('http://localhost/test/wsdl/hello.xml');
  $params = "Name";
  $response = $sClient->doHello($params);
  var_dump($response);
} catch(SoapFault $e){

  var_dump($e);
}
?>