如何在php或jquery中使用Nav Dynamics Soap Webservice?



我想从PHP或jquery使用Navision 2016 soap Web服务。 我已经尝试过这个解决方案PHP与动态导航网络服务

我有以下肥皂PHP代码:

<?php
if (extension_loaded('soap'))
{
// Request parameters :
// Exemple is a Nav Code unit GetSalesPrices, method GetPrice(CodPCustomerNo, CodPItemNo)
$NavUsername = "superUser";
$NavAccessKey = "passworddrowssap";
$CodeunitMethod = "CallMethod";
$params = array(
"employeeNo" => "CUSTOMER_1",
"leaveType" => "ITEM_1",
);
// SOAP request header
$url = "http://DESKTOP-H5GFAKH:7047/DynamicsNAV100/WS/MyCompany/Codeunit/webportals";
$options = array(
'authentication' => SOAP_AUTHENTICATION_BASIC,
'login' => $NavUsername,
'password' => $NavAccessKey,
'trace' => 1,
'exception' => 0,
);
try
{
$client = new SoapClient(trim($url), $options);
$soap_response = $client->__soapCall($CodeunitMethod, array('parameters' => $params));
echo "SOAP REQUEST SUCESS :";
var_dump($soap_response);
}
catch (SoapFault $soapFault)
{
echo "SOAP REQUEST FAILED :<br>";
var_dump($soapFault);
echo "Request :<br>" . htmlentities($soap_client->__getLastRequest()) . "<br>";
echo "Response :<br>" . htmlentities($soap_client->__getLastResponse()) . "<br>";
}
}
else
{
echo "Php SOAP extention is not available. Please enable/install it to handle SOAP communication.";
}
?>

有了这个,我得到:

肥皂错误:解析 WSDL:无法从 "http://DESKTOP-H5GFAKH:7047/DynamicsNAV100/WS/MyCompany/Codeunit/webportals" :无法加载外部实体

对于初学者来说,你可以使用POSTMAN,你可以得到你应该使用的代码。话虽如此,请参阅下面的代码。你不必使用SoapClient,只需在PHP中使用cURL。请确保在 Navision 中使用基本身份验证。以下示例是请求 NAV 从 NAV 列表中获取数据

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://URL:PORT/WebService/WS/COMPANY%20NAME/Page/WebService",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS =>"<?xml version="1.0" encoding="utf-8"?>n<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">n<Body>n<Read xmlns="urn:microsoft-dynamics-schemas/page/WebService">n<No>" .$entry_no. "</No>n</Read>n</Body>n</Envelope>",
CURLOPT_HTTPHEADER => array(
"Content-Type: text/xml; charset=utf-8",
"SoapAction: urn:microsoft-dynamics-schemas/page/WebService",
"Authorization: Basic " .base64_encode('username:password'). ""
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$xml = simplexml_load_string($response, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
$xml->registerXPathNamespace('soapenv', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('xmlns', 'urn:microsoft-dynamics-schemas/page/webservice');
$xmlinfo = $xml->xpath('Soap:Body');

来自Chrome Store或Firefox扩展的用户Wizdler,使您能够解析WSDL并生成SOAP消息。

对于jQuery,你可以使用POSTMAN来生成所需的代码,或者你应该考虑使用AJAX

相关内容

  • 没有找到相关文章

最新更新