为什么这个php类不起作用?

时间:2013-10-10 14:23:49

标签: php

我想把这些代码放在一起,但没有运气。无法弄清楚什么是失败的,因为我是初学者。

尝试:

通过SOAP协议向服务器发送请求。以前的工作代码首先被提及。

失败了什么?

我尝试发出请求,没有任何内容弹出。没有什么好事发生。抛出调试器上没有发现任何错误的代码。

以前的工作代码:

<?php
$client = new SoapClient('http://xxxxxxx.xxxxxxx.pt/xxxxxxx.asmx?WSDL');

$function = 'EditClient';

$arguments= array('EditClient' => array(
                        'empresa'   => 'xxxxx',
                        'password'      => '********',
                        'cliente'        => '19781978',
                        'nome'        => 'Justiceiro',
                        'morada'        => 'Avenida akolá',
                        'localidade'        => 'Integral',
                        'codPostal'        => '4000-100',
                        'pais'        => 'portugal',
                        'telefone'        => '253994257',
                        'fax'        => '000000000',
                        'telemóvel'        => '000000000',
                        'email'        => 'email@email.pt',
                        'nif'        => '000000000',
                        'contacto'        => 'none',
                ));
$options = array('location' => 'http://xxxxxx.xxxxxxx.pt/xxxxxx.asmx?WSDL');

$result = $client->__soapCall($function, $arguments, $options);

echo 'Response: ';
print_r($result);
?>

我最喜欢的是什么

到目前为止,这是我所得到的,似乎没有什么不合适的地方,但我再一次非常陌生。

<?php

class cliente{

    private $data;
    private $arguments;  
    private $function;  
    private $client;  
    private $result;

    function editcliente(){
        $this->data=array();
        $this->arguments=array();
    }

    public function setData($d){
        $this->data = $d;
    }

    public function validate(){
            $options = array('location' => 'http://xxxxxx.xxxxxxx.pt/xxxxxx.asmx?WSDL');
            $verifica = true;
            foreach ($this->data as $campo) {
                $this->data[$campo] = $_GET[$campo];
                    $arguments = array('EditCliente' => array(
                        'empresa'   => 'xxxxxx',
                        'password'      => '********',
                        'cliente'        => ' ',
                        'nome'        => ''.$this->data["fnome"].'',
                        'morada'        => ''.$this->data["fmorada"].'',
                        'localidade'        => ''.$this->data["flocalidade"].'',
                        'codPostal'        => '4000-100',
                        'pais'        => ''.$this->data["Portugal"].'',
                        'telefone'        => 'vazio',
                        'fax'        => 'vazio',
                        'telemóvel'        => ''.$this->data["ftelemovel"].'',
                        'email'        => ''.$this->data["femail"].'',
                        'nif'        => ''.$this->data["fnif"].'',
                        'contacto'        => ''.$this->data["empresa"].'',
                    ));
                }
            }
    }

    public function getData(){
        print_r($this->data);
        print_r($this->arguments);
    }

    public function sendrequest(){
        $client = new SoapClient('http://apimarvin.ponto25.pt/apimarvin.asmx?WSDL');
        $function = 'EditCliente';
        $result = $client->__soapCall($function, $arguments, $options);
    }   
}

$cliente = new cliente();
$campos = array('fnome','fmorada','flodalidade','fcodigopostal','ftelemovel','femail','fnif','fempresa');

$cliente->setData($campos);
echo ($cliente->validate($data));
echo ($cliente->getData($data));
$cliente->sendrequest($data);

?>

1 个答案:

答案 0 :(得分:0)

这就是我在PHP中调用SOAP函数的方法

在我的索引中:

$client = new SoapClient('http://localhost:8100/PortalService.svc?wsdl');

然后:

$arguments = array('argument' => $arg);
$response = $wcfclient->NameOfFunction($arguments);

简单明了。 希望这会对你有所帮助。