如何在PHP中使用Microsoft AX Web服务从Microsoft AX获取客户列表?

时间:2019-05-22 10:22:34

标签: php wordpress axapta dynamics-ax-2009

我已经在AX中完成了Web服务设置。现在,我想使用该Web服务来在PHP门户中显示客户。请查看下面的代码。

$soapUrl = "http://example.com/MicrosoftDynamicsAXAif50/woocommerceservice.svc?wsdl"; 
$soapUser = "xxxxxxxxxxxxxxxxx";  
$soapPassword = "xxxxxxxx"; 

$xml_post_string = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">                        
                        <s:Header>
                            <CallContext xmlns="http://schemas.microsoft.com/dynamics/2010/01/datacontracts">
                            <Company>001</Company>
                            <Language>en-us</Language>
                            </CallContext>
                        </s:Header>
                        <s:Body>
                            <WooCommerceServiceReadRequest xmlns="http://tempuri.org">
                                <EntityKeyList xmlns = "http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKeyList">                                 
                                </EntityKeyList>
                            </WooCommerceServiceReadRequest>                            
                        </s:Body>
                    </s:Envelope>';   

$headers = array(
            "Content-type: text/xml;charset=\"utf-8\"",
            "Accept: text/xml",
            "Cache-Control: no-cache",
            "Pragma: no-cache",
            "SOAPAction: http://tempuri.org/WooCommerceService/read", 
            "Content-length: ".strlen($xml_post_string),
        ); 

$url = $soapUrl;

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); 
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); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch); 
$info = curl_getinfo($ch);
if (curl_error($ch)) {
    $error_msg = curl_error($ch);
}
curl_close($ch);
print_r($response);

它返回“ Original001”。请检查并提出建议。

谢谢。

0 个答案:

没有答案
相关问题