dynamic NAV 2016 Web服务:服务*中的方法*中的参数*为空


Dynamics NAV 2016 Web Service: Parameter * in method * in service * is null

我尝试从我的Dynamics Nav Web服务(Dynamics Nav 2016)中获得单个联系人。我使用PHP中的soap请求来完成此操作。

web服务是一个包含两个函数的代码单元:

fGetContact(iContactNumber : Text[20]) oContact : Text[250]
IF rContact.GET(iContactNumber) THEN BEGIN
  oContact := '';
  oContact := rContact."No." + ';' +
              rContact."Company Name" + ';' +
              rContact."First Name" + ';' +
              rContact.Surname + ';' +
              rContact."E-Mail";
END;
EXIT(oContact);
fGetContacts() oContacts : Text[250]
IF rContact.GET('KT100190') THEN BEGIN
  oContacts := '';
  oContacts := rContact."No." + ';' +
               rContact."Company Name" + ';' +
               rContact."First Name" + ';' +
               rContact.Surname + ';' +
               rContact."E-Mail";
END;
EXIT(oContacts);

第二个函数fGetContacts工作得很好。但是,当我使用联系电话作为参数调用fGetContact时,它返回以下错误:

Parameter iContactNumber in method FGetContact in service MyService is null!

我像下面这样使用NTLMSoapClient:

<?php
ini_set('soap.wsdl_cache_enabled', '0'); 
require_once 'ntlmstream.php';
require_once 'ntlmsoapclient.php';
$url = 'http://localhost:7047/DynamicsNAV90/WS/CRONUS/Codeunit/MyService';
$options = array(
    'uri' => $url,
    'location' => $url,
    'trace' => true,
    'login' => 'my_user',
    'password' => 'my_password'
);
// we unregister the current HTTP wrapper
stream_wrapper_unregister('http');
// we register the new HTTP wrapper
stream_wrapper_register('http', 'MyServiceProviderNTLMStream') or die("Failed to register protocol");
// so now all request to a http page will be done by MyServiceProviderNTLMStream.
// ok now, let's request the wsdl file
// if everything works fine, you should see the content of the wsdl file
$client = new MyServiceNTLMSoapClient(null, $options);
// should display your reply
try {
    $params = array('iContactNumber' => 'KT100190');
    echo '<pre>';
    echo $client->FGetContacts(); // works
    echo $client->FGetContact($params); // doesn't work
    echo '</pre>';
} catch (SoapFault $e) {
    echo '<pre>';
    var_dump($e);
    echo '</pre>';
}
// restore the original http protocole
stream_wrapper_restore('http');

我也试着像这样调用这个函数:

echo $client->FGetContact('KT100190');

返回错误与之前相同。

我用SoapUI测试了我的函数,返回值正是它应该是什么。

请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:new="urn:microsoft-dynamics-schemas/codeunit/MyService">
   <soapenv:Header/>
   <soapenv:Body>
      <new:FGetContact>
         <new:iContactNumber>KT100190</new:iContactNumber>
      </new:FGetContact>
   </soapenv:Body>
</soapenv:Envelope>

反应:

<Soap:Envelope xmlns:Soap="http://schemas.xmlsoap.org/soap/envelope/">
   <Soap:Body>
      <FGetContact_Result xmlns="urn:microsoft-dynamics-schemas/codeunit/MyService">
         <return_value>KT100190;Add-ON Marketing;Chris;McGurk;chris.mcgurk@cronuscorp.net</return_value>
      </FGetContact_Result>
   </Soap:Body>
</Soap:Envelope>

那么我做错了什么,这个错误出现,我该如何修复它?

无论如何,我遇到了这个问题,并通过向soap客户机的选项中添加"cache_wsdl" => WSDL_CACHE_NONE来解决它。

由于更新WSDL后缓存问题,一些字段丢失。

我做了一个变通方法,现在它对我有用了。

我改变了NTLMSoapClient类中的$request变量,因为php发送给我的服务的soap信封是绝对无用的。

基本上我在旋度动作之前做了这个:

$request = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:new="urn:microsoft-dynamics-schemas/codeunit/MyService">
               <soapenv:Header/>
               <soapenv:Body>
                  <new:FGetContact>
                     <new:iContactNumber>'.$this->iContactNumber.'</new:iContactNumber>
                  </new:FGetContact>
               </soapenv:Body>
            </soapenv:Envelope>';

(如果有人有同样的问题,尝试var_dump($request)并在浏览器中查看源代码。)您将看到PHP在那里做了什么…)