2009-10-21 34 views
6

我想用php创建新的联系人和线索。我无法弄清楚如何调用mscrm 3 web服务的方法。通过PHP Soap的Microsoft CRM 3.0 Web服务类

php肥皂类似乎很简单的使用。我能够连接并认证到crm web服务并获取可用函数的列表,但我不确定如何去调用它们。

我看到了mscrm 4.0的例子,它似乎涉及大量的XML,包括肥皂标题和信封。

我的印象是使用soap类绕过了这一点,并将为我写所有额外的XML,所以我需要做的就是调用一个参数数组的函数?

我完全错了吗?

有没有人用mscrm 3做过这件事,可以提供一些示例代码,或者可以给我几点提示,指出如何正确调用Create()方法?

回答

3

我已经能够使用的NuSOAP和施工后的XML消息作为系列使用的发送方法,而不是调用的字符串得到这个工作。这现在按预期工作。似乎使用调用方法返回的是不同于ms crm 3 web服务所需的XML。

2

任何体面的SOAP工具包都会自动地吐出正确的XML。看看这个家伙:

http://us2.php.net/xmlrpc_encode_request

+0

我使用PHP Soap类,我真的很麻烦是知道什么参数传递给create()方法格式正确。 – Ben 2009-10-22 05:24:53

2
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); 
    } 
}