通过PHP进行SOAP请求

时间:2019-04-10 06:52:47

标签: php soap wsdl soap-client

我试图为SOAP wsdl创建一个请求,请求和请求的响应是:

SOAP请求:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sub="http://subscriberprovisioning.ws.nvsmx.domain.com/">
<soap:Header/><soap:Body>
<sub:wsGetSubscriberProfileByID><subscriberID>123456789</subscriberID><alternateID></alternateID><parameter1></parameter1><parameter2></parameter2>
</sub:wsGetSubscriberProfileByID></soap:Body></soap:Envelope>

回复

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:wsGetSubscriberProfileByIDResponse xmlns:ns2="http://subscriberprovisioning.ws.nvsmx.domain.com/">
<return><responseCode>200</responseCode><responseMessage>SUCCESS</responseMessage><subscriberProfile>
<entry><key>SUBSCRIBER_IDENTITY</key><value>123456789</value></entry>
</subscriberProfile></return></ns2:wsGetSubscriberProfileByIDResponse></soap:Body></soap:Envelope>

我正在使用php创建请求,代码看起来像这样:

request.php

<?php

$client = new SoapClient("http://ipnumber:1988/services/Subscriber?wsdl"); 





$param = array('subscriberId' => '123456789');
$response = $client->wsGetSubscriberProfileByID    ($param);

var_dump($response);

在以上代码中,'subscriberId' => '123456789'没有传递给wsdl,并且我得到了缺少的参数响应。我也使用SOAP UI进行了测试,并且可以正常工作。任何有关我的php代码的建议。

谢谢

1 个答案:

答案 0 :(得分:0)

最后,它在此代码内起作用了:

try{
$soapclient = new SoapClient('http://ipnumber:1988//services/Subscriber?wsdl');
$param=array('subscriberID'=>'123456789');
$response =$soapclient->wsGetSubscriberProfileByID($param);
var_dump($response);
echo '<br><br><br>';
$array = json_decode(json_encode($response), true);
print_r($array);
 echo '<br><br><br>';
      echo '<br><br><br>';
    foreach($array as $item) {
        echo '<pre>'; var_dump($item);
    }  
}catch(Exception $e){
    echo $e->getMessage();
}