使用包含Document / literal的NuSoap PHP调用SOAP客户端

时间:2015-06-29 11:45:05

标签: php soap nusoap

我试图进行SOAP调用,但是遇到了很多问题。

我正在使用这个:

$client = new nusoap_client('http://odigo.xxx.com/xxx/servlet/services/WebCallBack?wsdl'); 
$client -> setEndpoint('https://odigo2.xxx.com/xxx/servlet/services/WebCallBack.WebCallBackHttpSoap11Endpoint/'); 

$client->soap_defencoding = 'UTF-8';

error message:
$error = $client->getError();

if ($error) {
die("client construction error: {$error}\n");
}

$param = array('skillKeyWord' => 'yyy',
             'phoneNumber' => '999999999',
             'user' => 'XXX',
             'password' => 'XXX',
            );
$result = $client->call('saveCallBack', array('parameters' => $param), '', '', false, true);

客户的IT部门告诉我,请求是错误的,因为:"需要使用Document / literal包装,而不是编码"和"参数封装错误"

他们发送给我们的正确电话就是这个例子:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <saveCallBack xmlns ="http://odigo.xxx.com/2009/09/21/webcallback.xsd" xmlns:ns2="http://webcallback.ws.bean.model.odigo.xxx.com/xsd" xmlns:ns3="http://administration.bean.model.odigo.xxx.com/xsd">
         <webCallBack>
            <ns2:date>0</ns2:date>
            <ns2:phoneNumber>9999999</ns2:phoneNumber>
            <ns2:skillKeyWord>yyy</ns2:skillKeyWord>
         </webCallBack>
         <user>
            <ns3:login>XXX</ns3:login>
            <ns3:password>XXX</ns3:password>
         </user>
      </saveCallBack>
   </soap:Body>
</soap:Envelope>

我不知道如何使用nusoap发送此格式调用,或使用此XML使用nusoap进行调用。

任何帮助它的赞赏。

1 个答案:

答案 0 :(得分:1)

尝试使用CURL。代码如下所示:

$soap_body   = '<?xml version="1.0" encoding="utf-8"?>'.
            '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'.
                '<soap:Body>'.
                    '<saveCallBack xmlns ="http://odigo.xxx.com/2009/09/21/webcallback.xsd" xmlns:ns2="http://webcallback.ws.bean.model.odigo.xxx.com/xsd" xmlns:ns3="http://administration.bean.model.odigo.xxx.com/xsd">'.
                        '<webCallBack>'.
                            '<ns2:date>0</ns2:date>'.
                            '<ns2:phoneNumber>9999999</ns2:phoneNumber>'.
                            '<ns2:skillKeyWord>yyy</ns2:skillKeyWord>'.
                        '</webCallBack>'.
                        '<user>'.
                            '<ns3:login>XXX</ns3:login>'.
                            '<ns3:password>XXX</ns3:password>'.
                        '</user>'.
                    '</saveCallBack>'.
                '</soap:Body>'.
            '</soap:Envelope>'; 

$headers = array
( 
   'Content-Type: text/xml; charset="utf-8"', 
   'Content-Length: '. strlen($soap_body), 
   'Accept: text/xml', 
   'Cache-Control: no-cache', 
   'Pragma: no-cache'
);

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, 'http://odigo.xxx.com/xxx/servlet/services/WebCallBack?wsdl'); 
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soap_body); 

$result = curl_exec($ch);
//do something useful with $result variable