我想通过PHP或jquery使用Navision 2016 soap Web服务。我已经尝试过此解决方案PHP with Dynamics NAV webservices
我有以下用于肥皂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.";
}
?>
有了这个我得到:
SOAP-ERROR:解析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商店中的用户Wizdler,您可以解析WSDL并生成SOAP消息