2016-10-22 4 views
1

Hallo Kann mir jemand bei der Implementierung unter SOAP XML in PHP erklären, sah ich einige Fragen, die mit CURL behandelt wurden, aber ich möchte SoapClient-Bibliothek in PHP verwenden Kann mir helfen.Soap-Client in PHP

sah ich einige Leute unter Code in PHP bekommen die einfachen SOAP verwendet, Wie kann ich

<?php 
//Create the client object 
$soapclient = new SoapClient('http://www.example.com:8080/test/services/test?wsdl'); 

//Use the functions of the client, the params of the function are in 
//the associative array 
$params = array(
'locationID' => '19087525238255', 
'custFirstName' => 'Seure', 
'custLastName' => 'Install', 
'customerType' => 'RESI' 
); 
$response = $soapclient->octService($params); 

var_dump($response); 

?> 

SOAP XML

<soapenv:Envelope xmlns:soapenv = "http://schemas.xmlsoap.org/soap/envelope/" xmlns:com = "http://test.com/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <com:OCTService> 
      <locationID>19087525238255</locationID> 
      <customer> 
       <custFirstName>JOHN</custFirstName> 
       <custLastName>ADAM</custLastName> 
       <customerType>RESI</customerType> 
      </customer> 
      <order> 
       <orderScheduleType>NoSchedule</orderScheduleType> 
       <orderScheduledate/> 
       <reasonCode>NT</reasonCode> 
       <salesRep>0001</salesRep> 
      </order> 
      <Equipments> 
       <equipment> 
        <serialNumber>*</serialNumber> 
        <type>N</type> 
       </equipment> 
       <equipment> 
        <serialNumber>*</serialNumber> 
        <type>NH</type> 
       </equipment> 
       <equipment> 
        <serialNumber>*</serialNumber> 
        <type>NH</type> 
       </equipment> 
      </Equipments> 
      <csgServiceCodes> 
       <CSGServiceCode> 
        <rateCode>SR002</rateCode> 
        <packageCode/> 
       </CSGServiceCode> 
       <CSGServiceCode> 
        <rateCode>BA</rateCode> 
        <packageCode/> 
       </CSGServiceCode> 
      </csgServiceCodes> 
      <voiceFeatures> 
       <nativeNumbersCount>0</nativeNumbersCount> 
       <portedNmbers>?</portedNmbers> 
      </voiceFeatures> 
      <HuntGroup> 
       <huntGroupType>?</huntGroupType> 
      </HuntGroup> 
     </com:OCTService> 
    </soapenv:Body> 
</soapenv:Envelope> 

Antwort

1

ich nicht in der Lage mit der gleichen Art und Weise in meinem Code implementieren zu erreichen CURL POST.

Hier Wichtigste ist Soapaction, die Sie im WSDL-Dokument verwenden können

$headers = array(
    "Accept-Encoding: gzip,deflate", 
    "Content-Type: text", 
    "Cache-Control: no-cache", 
    "Username: yourusername", 
    "Password: password",     
    "SOAPAction: urn:OCTService", 
    "Content-length: ".strlen($xml_post_string), 
    ); //SOAPAction: your op URL 


    $ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
//curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

// converting 
$response = curl_exec($ch); 
echo $response; 
curl_close($ch); 

// converting 
$response1 = str_replace("<soap:Body>","",$response); 
$response2 = str_replace("</soap:Body>","",$response1); 

// convertingc to XML 
$parser = simplexml_load_string($response2);