PHP SOAP将包络发送到WSDL

时间:2016-07-27 19:15:43

标签: php curl soap wsdl soap-client

我真的希望我能为此写出正确的标题。基本上,我需要连接以向某个URL发送soap请求,并从那里检索数据。

这是我需要发送的请求:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:rad="http://schemas.datacontract.org/2004/07/Radixx.ConnectPoint.Request" xmlns:rad1="http://schemas.datacontract.org/2004/07/Radixx.ConnectPoint.Security.Request">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:RetrieveSecurityToken>
         <!--Optional:-->
         <tem:RetrieveSecurityTokenRequest>
            <rad:CarrierCodes>
               <!--Zero or more repetitions:-->
               <rad:CarrierCode>
                  <rad:AccessibleCarrierCode>FZ</rad:AccessibleCarrierCode>
               </rad:CarrierCode>
            </rad:CarrierCodes>
            <rad1:LogonID>xxx</rad1:LogonID>
            <rad1:Password>xxxx</rad1:Password>
         </tem:RetrieveSecurityTokenRequest>
      </tem:RetrieveSecurityToken>
   </soapenv:Body>
</soapenv:Envelope>

这是我的代码

$url = "http://uat.ops.connectpoint.flydubai.com/ConnectPoint.Security.svc?wsdl";
$data =  array(  "LogonID"=>"xxxxx",  "Password"=>"xxxxx");

$client = new SoapClient($url);

$client->__soapCall("RetrieveSecurityToken", $data);

请求错误

Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed] The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'RetrieveSecurityToken'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 162. in J:\WORK\web\flyDubai\index.php:25 Stack trace: #0 J:\WORK\web\flyDubai\index.php(25): SoapClient->__soapCall('RetrieveSecurit...', Array) #1 {main} thrown in J:\WORK\web\flyDubai\index.php on line 25`

当我调用__getTypes()时,我得到(除其他外):

struct RetrieveSecurityToken {
    string LogonID;
    string Password;
}

我猜这个请求是不正确的(也许我应该将整个xml转换为数组),但是我无法弄清楚如何发送正确的?

1 个答案:

答案 0 :(得分:0)

您正在调用的方法需要RetrieveSecurityTokenRequest类型RetrieveSecurityToken参数,该参数在包含的XSD file中定义。在那里,您可以看到它是CarrierInfo添加LogonIDPassword属性的扩展。

基本类型CarrierInfo在其他XSD file中定义。它具有CarrierCodes类型的单个属性ArrayOfCarrierCode,它是CarrierCode个对象的数组,每个对象都有一个AccessibleCarrierCode字符串属性。

在WSDL中,CarrierInfo被指定为nillable(允许<rad:CarrierCodes xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />)并且可以是空数组(允许<rad:CarrierCodes/>),但在这些情况下服务正在回复错误。

这就是为什么您应该根据您在问题中发布的示例XML创建请求,至少有一个运营商代码:

$code = new StdClass;
$code->AccessibleCarrierCode = "FZ";

$data = new StdClass;
$data->CarrierCodes = array($code);

$data->LogonID = "xxxxx";
$data->Password = "xxxxx";

$client = new SoapClient($url);
$response = $client->RetrieveSecurityToken(array("RetrieveSecurityTokenRequest" => $data));

var_dump($response);