将PHP客户端连接到Web服务Microsoft Dynamic 365

时间:2019-06-27 12:18:36

标签: php ntlm

我正在尝试使用php创建一个客户端,以将数据发送到提供Microsoft动态365的Web服务,我认为它需要身份验证,但是我无法加载wsdl

我正在使用SoapClient类,有人在使用此类进行通信

define('URL','https://buildpinfraaos.sandbox.ax.dynamics.com/soap/services/FesLedgerJournalWs?singleWsdl');

error_reporting(E_ALL ^ E_NOTICE);
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);



$opts = array( 'http' => array( 'user_agent' => 'PHPSoapClient' ) );
$soapClientOptions = array(
        'stream_context' => $context,
        'cache_wsdl' => WSDL_CACHE_NONE,
      //  'login' => ' wsuser@Pinfra.onmicrosoft.com', 'password' => 'Mun75565'
    );

   $datos =  array(); 
   try { 
        $client = new SoapClient(URL, $soapClientOptions ); 

        $resultado = $client->__getFunctions();
        //highlight_string($client->__getLastRequest());

       // $resultado = $client->FesCreateLedgerJournal(); 
         var_dump($resultado); 
    } catch (SoapFault $exception) {  
        echo "Error: ",$exception->getMessage()."<br>";
        /* 
        var_dump($client->__getLastRequest())."<br>";
        var_dump($client->__getLastResponse())."<br>";*/
    } 

我了解我必须收到一个xml并发送一个xml,但是在上传时会出现此错误:

错误:SOAP错误:解析WSDL:无法从“ https://buildpinfraaos.sandbox.ax.dynamics.com/soap/services/FesLedgerJournalWs?singleWsdl”加载:无法加载外部实体“ https:// buildpinfraaos。sandbox.ax.dynamics.com/soap/services/FesLedgerJournalWs? singleWsdl“

1 个答案:

答案 0 :(得分:0)

最终的解决方案是:

require_once "lib/nusoap.php";


    $rul = 'https://xxxxxxxxx.sandbox.ax.dynamics.com/soap/services/FesLedgerJournalWs?singleWsdl';  
    $innerNS = 'http://schemas.microsoft.com/dynamics/2013/01/datacontracts'; 

    $access_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkN0ZlFDOExlLThOc0M3b0MyelFrWnBjcmZPYyIsImtpZCI6Ik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10GoYAjDpbjdww';
    $httpHeaders = array(
    'http' => array(
        'protocol_version' => 1.1,  
        'header' => "Authorization:Bearer " . $access_token . "\r\n",
    ));
    // form a stream context
    $context = stream_context_create($httpHeaders);
    // pass it in an array
    $params = array('stream_context' => $context);

try{
    $soap = new SoapClient($rul, $params);  
    //$soap->addPatientWs("tok", "1243");


    $auth = new stdClass();
    $auth->Company = 'DAT';
    $auth->Language = 'es-mx';
    $auth->MessageId = 'BCE4B0A7-C794-4FBA-A403-E1ECB0C1B968';
    $auth->PartitionKey = 'Initial';

    $header = new SoapHeader($innerNS , 'CallContext', $auth, false);

    $soap->__setSoapHeaders($header); 

    $param = array ('FesCreateLedgerJournal' => array("xmlFileStr" => "?"));

    $result = $soap->__soapCall("FesCreateLedgerJournal",   $param);


      var_dump($result); 

}catch(SoapFault $e){
    echo "Error-Exception:".$e->getMessage()."\n\n";
    var_dump( $soap->__getLastRequestHeaders());
    var_dump( htmlspecialchars($soap->__getLastRequest()));
}