首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php -使用web服务访问dynamics crm 2011

php -使用web服务访问dynamics crm 2011
EN

Stack Overflow用户
提问于 2013-06-08 07:12:17
回答 1查看 3K关注 0票数 17

我必须通过web服务访问crm 2011中的销售线索(创建新销售线索并获取列表)。我已经用c#/asp.net做了一个应用程序(它可以工作),但是现在我必须用php来做,我被卡住了。

我尝试了:https://code.google.com/p/php-dynamics-crm-2011/,但它不工作,因为它只支持联合身份验证,而我的身份验证是active directory。

我试图连接到nusoap,但它非常令人困惑。

我使用wsdl2php:http://www.urdalen.no/wsdl2php/生成发现服务和组织服务的类,但我不知道如何处理这些类。

有没有人举例说明如何使用这些类?

EN

回答 1

Stack Overflow用户

发布于 2014-03-04 19:28:38

MSCRM 2013和2011可能正在使用NTLM对the服务进行身份验证。

对于数据查询,可以使用url编码的FetchXML。

http://msdn.microsoft.com/en-us/library/gg328117.aspx

例如,您可以通过在Advanced search中导出XML来从CRM中获取正确的XML,并使用RetrieveMultiple方法执行查询。

我正在添加一个使用SOAP信封和CURL POST查询的示例,并使用NTLM进行身份验证。

代码语言:javascript
复制
<?php

$soap_envelope = <<<END
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <RetrieveMultiple xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <query i:type="a:FetchExpression" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
        <a:Query>&lt;fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'&gt;
          &lt;entity name='contact'&gt;
            &lt;attribute name='fullname' /&gt;
            &lt;attribute name='parentcustomerid' /&gt;
            &lt;attribute name='telephone1' /&gt;
            &lt;attribute name='emailaddress1' /&gt;
            &lt;attribute name='contactid' /&gt;
            &lt;order attribute='fullname' descending='false' /&gt;
            &lt;filter type='and'&gt;
              &lt;condition attribute='ownerid' operator='eq-userid' /&gt;
              &lt;condition attribute='statecode' operator='eq' value='0' /&gt;
            &lt;/filter&gt;
          &lt;/entity&gt;
        &lt;/fetch&gt;</a:Query>
      </query>
    </RetrieveMultiple>
  </s:Body>
</s:Envelope>
END;

$soap_action = 'http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple';
$req_location = 'http://crm.server.local/YourOrganization/XRMServices/2011/Organization.svc/web';

$headers = array(
  'Method: POST',
  'Connection: Keep-Alive',
  'User-Agent: PHP-SOAP-CURL',
  'Content-Type: text/xml; charset=utf-8',
  'SOAPAction: "'.$soap_action.'"'
);

$user = 'YOURDOMAIN\YOURUSERNAME';
$password = '**********';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $req_location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $soap_envelope);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password);
$response = curl_exec($ch);

if(curl_exec($ch) === false)
{
  echo 'Curl error: ' . curl_error($ch);
}
else
{
  var_dump($response);
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16994238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档