【问题标题】:how can i use the function CREATE in soap webservice in Navision in PHP?我如何在 PHP 的 Navision 中使用 Soap Web 服务中的 CREATE 函数?
【发布时间】:2014-11-27 12:51:09
【问题描述】:

Here 你可以查看文档。它在 C# 中。我尝试使用 PHP 制作一个工作示例。我设法在 PHP 中执行 Read & ReadMultiple 函数。这是我的尝试:

   require ("./NTLMSoapClient.php");
    $client = new NTLMSoapClient(null, array(
        'cache_wsdl' => WSDL_CACHE_NONE,
        'trace' => true,
        'location' => "http://83.166.204.26:7147/TEST/WS/Harmont%20Blaine_TEST/Page/WebItem",
        'uri' => "urn:microsoft-dynamics-schemas/page/webitem",

    ));
    $client->user = "xxxxxx";
    $client->password = "xxxxxxxxx";
 try{

    $resp = $client->Create(new SoapVar('555554', XSD_STRING, null, null, 'ns1:No' ));
    echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
}catch(SoapFault $sf){
    //echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
    print '<pre>';
    print_r($sf); 
    print '</pre>'; 
}
print '<pre>';var_dump($resp);  print '</pre>';

由于某种原因它返回我 NULL。知道为什么不工作吗?

【问题讨论】:

    标签: php web-services soap navision


    【解决方案1】:

    Freddy Kristiansen 撰写了一系列精彩的博文,详细解释了如何从不同环境连接到 Nav Web 服务。

    第一部分在这里: Connecting to NAV Web Services from …

    第二部分: Connecting to NAV Web Services from PHP

    客户端可以收到 NULL 响应有几个原因。首先 - 客户端应用程序无法在 Web 服务上进行身份验证。如果服务器端使用 SPNEGO 协议而不是 NTLM,就会发生这种情况。您需要在 CustomSettings.config 中设置密钥“ServicesUseNTLMAuthentication”,正如 Freddy 在他的第一篇文章中所述。

    如果可以从服务中读取数据,但无法创建记录,则说明请求成功通过认证,问题可能出在SOAP消息格式上。

    这是 Nav 期望在创建请求中收到的内容

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <soap:Body>
            <Create xmlns="urn:microsoft-dynamics-schemas/page/customer">
                <Customer>
                    <No>555554</No>
                    <Name>NewCustomer</Name>
                </Customer>
            </Create>
        </soap:Body>
    </soap:Envelope>
    

    要实现此结果,您可以将标准 HTTP 流包装器替换为 NTLMStream 包装器(请参阅上面的文章“从 PHP 连接到 NAV Web 服务”。

    现在,您只需执行以下操作即可读取客户记录:

    $client = new NTLMSoapClient("http://192.168.0.101:7047/DynamicsNAV71/WS/".rawurlencode($company)."/Page/Customer");
    $resp = $client -> Read(array('No' => '10000'));
    

    创建新记录也变得更加容易:

    $client = new NTLMSoapClient("http://192.168.0.101:7047/DynamicsNAV71/WS/".rawurlencode($company)."/Page/Customer");
    
    class CustomerWrapper
    {
        public $Customer;
    }
    
    $cw = new CustomerWrapper;
    $cw -> Customer -> No = "555554";
    $cw -> Customer -> Name = "NewCustomerName";
    $cw -> Customer -> E_Mail = "john.doe@cronuscorp.net";
    $resp = $client -> Create($customer);
    

    【讨论】:

    【解决方案2】:

    这是解决方案:

    $resp = $client->Create(new SoapVar('5555195', XSD_STRING, null, null, 'ns1:WebItem' ));
    

    我必须将 No 更改为 WebItem

    看这里:

    <xsd:element name="Create">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element minOccurs="1" maxOccurs="1" name="WebItem" type="tns:WebItem"/></xsd:sequence></xsd:complexType>
    </xsd:element>
    

    【讨论】:

      猜你喜欢
      • 2021-05-01
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      • 2016-09-30
      • 1970-01-01
      • 2012-03-01
      • 1970-01-01
      • 2013-09-23
      相关资源
      最近更新 更多