在PHP中,我如何在Navision的soap webservice中使用函数CREATE?

问题描述 投票:0回答:3

下面是 你可以看到文档。我试着用PHP做一个工作的例子。我设法执行 读取& 读取多个 在PHP中的函数。这是我的尝试。

   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
3个回答
1
投票

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

第一部分在这里。连接到NAV网络服务从....

第二部分:从PHP连接到NAV Web服务从PHP连接到NAV网络服务

客户端可能会收到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>

为了达到这个结果,你可以用NTLMStream包装器代替标准的HTTP流包装器(参见上面的帖子 "从PHP连接到NAV网络服务")。

现在,这就是你需要做的读取客户记录的全部工作。

$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 = "[email protected]";
$resp = $client -> Create($customer);

0
投票

这就是解决方案。

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

我必须改变 没有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>
© www.soinside.com 2019 - 2024. All rights reserved.