简体   繁体   English

通过PHP Soap类的Microsoft CRM 3.0 Web服务

[英]Microsoft CRM 3.0 web service via PHP Soap class

I would like to create new contacts and leads using php. 我想用php创建新的联系人和潜在客户。 I can't quite figure out how to call the methods of the mscrm 3 web service. 我无法弄清楚如何调用mscrm 3 Web服务的方法。

The php soap class seems quite simple to use. php soap类似乎很简单易用。 I am able to connect and authenticate to the crm web service and get a list of available functions however I am unsure how to go about calling them. 我能够连接并验证crm Web服务并获取可用功能列表,但我不确定如何调用它们。

I have seen examples for mscrm 4.0 which seem to involve masses of XML including soap headers and envelopes. 我见过mscrm 4.0的例子,它们似乎涉及大量的XML,包括soap标题和信封。

I am under the impression that using a soap class bypasses this and will write all the extra xml for me so all I need to do is call a function with an array of parameters? 我的印象是使用soap类会绕过这个并且会为我编写所有额外的xml所以我需要做的就是调用带有参数数组的函数?

Am I completely wrong here ? 我在这里完全错了吗?

Has anyone done this with mscrm 3 that can provide some sample code, or perhaps give me a few pointers as how to correctly call the Create() method ? 有没有人用mscrm 3做过这个,可以提供一些示例代码,或者给我一些关于如何正确调用Create()方法的指针?

I have been able to get this working by using Nusoap and after construction the XML message as a series of strings using the send method instead of call. 我已经能够通过使用Nusoap并使用send方法而不是call之后将XML消息构造为一系列字符串。 This now works as expected. 这现在按预期工作。 It seemed that using the call method was returning different XML than what was required by the ms crm 3 web service. 似乎使用call方法返回的不同于ms crm 3 Web服务所需的XML。

Any decent SOAP toolkit will automagically spit out the correct XML. 任何体面的SOAP工具包都会自动吐出正确的XML。 Check out this guy: 看看这家伙:

http://us2.php.net/xmlrpc_encode_request http://us2.php.net/xmlrpc_encode_request

require_once ('/var/mtp/lib/vendor/nusoap/lib/nusoap.php');

$login ='domain\username';
$pass ='password';
$useCURL = true;

$client = new nusoap_client('http://server:5555/mscrmservices/2006/crmservice.asmx?wsdl', 'wsdl');
$client->setCredentials($login, $pass, 'ntlm');
$client->setUseCurl($useCURL);
$client->useHTTPPersistentConnection();
$client->soap_defencoding = 'UTF-8';

$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
    exit();
}

$soapHeader='<soap:Header>' .
        '<CallerId xmlns="http://schemas.microsoft.com/crm/2006/WebServices">'.
        '<CallerGuid xmlns="http://schemas.microsoft.com/crm/2006/CoreTypes">00000000-0000-0000-0000-000000000000</CallerGuid></CallerId>' .
    '</soap:Header>';

$soapBody='<soap:Body>' .
    '<entity xmlns="http://schemas.microsoft.com/crm/2006/WebServices"  xsi:type="lead">' .
        '<ownerid type="Owner">2408c7dc-c0a3-dd11-b3cd-001a4bd3009a</ownerid>' .         
        '<firstname>Fred</firstname>' .
        '<lastname>Bloggs</lastname>' .
    '</entity>' .
    '</soap:Body>';


$xml = '<?xml version="1.0" encoding="utf-8"?>' .
    '<soap:Envelope' .          
        ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
        ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' .
        ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' .
    $soapHeader .
    $soapBody .
    '</soap:Envelope>';

//SOAP call
$result = $client->send($xml,'http://schemas.microsoft.com/crm/2006/WebServices/Create' );

//result
if ($client->fault) { //check for fault
    echo '<p><b>Fault: ';        
    print_r($result);        
    echo '</b></p>';
}

else { //no fault
    $err = $client->getError();
    if ($err) { // error
        echo 'Error: ' . $err . '';
        echo "\n\n# # # # # # # Request # # # # # # #\n";
        var_dump($client->request);
        echo "\n\n# # # # # # Response # # # # # # #\n";
        var_dump($client->response);
    }
    else { // display the result
    print_r($result);
    }
}

I was also struggling to get Dynamics CRM SOAP working with PHP but after a while I managed to get it working; 我也在努力让Dynamics CRM SOAP与PHP一起工作,但过了一段时间我设法让它工作; http://www.ifc0nfig.com/working-with-microsoft-dynamics-crm-4-0-soap-interface-with-php-and-nusoap/ - You can download a small class I created which may be of use :) http://www.ifc0nfig.com/working-with-microsoft-dynamics-crm-4-0-soap-interface-with-php-and-nusoap/ - 您可以下载我创建的可能有用的小班级:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM