0

PHP で SOAP 応答を取得しようとしています。xml としてではなく、オブジェクトとして Web ブラウザに表示され続けます。WSDL は XML として表示されますが、受信した応答は表示されません。以下は私のサーバー側のコードです。SOAP サーバーは 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

これは、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 に答える