使用SOAP和PHP创建XML节点

时间:2014-05-29 18:13:57

标签: xml soap nodes

我需要生成一个类似于这样的SOAP请求:

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
<s11:Body>

  <ns1:SaveQuote xmlns:ns1='http://domain.com/BDB/'>
     <ns1:ClientType></ns1:ClientType>

      <ns1:Claims>
        <ns1:ClaimHistory>
          <ns1:Nature></ns1:Nature>
        </ns1:ClaimHistory>
      </ns1:Claims>

   <ns1:Vehicles>
    <ns1:Vehicle>
      <ns1:Province></ns1:Province>
    </ns1:Vehicle>
  </ns1:Vehicles>

    </ns1:SaveQuote>
  </s11:Body>
 </s11:Envelope> 

我有:

 $url  = 'http://somedomain.com/soapurl.asmx?WSDL';
   try {  

    $client = new SoapClient($url);
    $saveQuote = array('ClientType' => $clientType);
    $claims = array('Nature' => $Nature);
    $vehicles = array('Province' => $Province)

     $response = $client->__soapCall(
'SaveQuote', array('parameters' =>$saveQuote), 
'Claims', array('ClaimHistory' =>$claims), 
   'Vehicles', array('Vehicle' => $vehicles));


var_dump($response);
    } catch (Exception $SoapException) {                           
    printf('Errors:\n',$SoapException->__toString());
    return false;                              
   } 

但这只会产生错误..如何让请求中的节点正确?

1 个答案:

答案 0 :(得分:0)

您应该使用与所需参数类型匹配的对象。为此,您可以使用WSDL到php生成器,这将简化为每个参数类型生成每个必需类的过程。它允许您使用类映射SoapClient选项,因此您还可以作为PHP对象获得响应,这比数组更容易...

我建议您查看WsdlToPhp或甚至网站WSDL to php