Dynamics NAV 2016 Web服务:service * in service *中的参数*为null

时间:2016-09-07 14:06:49

标签: php microsoft-dynamics navision microsoft-dynamics-nav dynamics-nav-2016

我尝试从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>

那么我错误地发现了这个错误,我该如何修复呢?

2 个答案:

答案 0 :(得分:1)

为了它的价值,我遇到了这个问题并通过添加“cache_wsdl”=&gt;解决了这个问题。 WSDL_CACHE_NONE到soap客户端的选项。

由于更新WSDL后出现缓存问题,某些字段丢失了。

答案 1 :(得分:0)

我做了一个解决方法,它现在适用于我。

我更改了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在那里做了多少麻烦......)