0

我正在尝试在 php 中获得肥皂响应。它不断作为一个对象出现在我的网络浏览器上,而不是作为 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);
}
4

2 回答 2

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);
}
?>
于 2013-06-20T11:22:51.663 回答
0

这是我如何使用 SoapClient 处理函数的示例:

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

希望这会帮助你。

于 2013-06-20T09:38:25.560 回答