PHP-使用Web服务访问Dynamics CRM 2011 [英] php - access dynamics crm 2011 with web services

查看:56
本文介绍了PHP-使用Web服务访问Dynamics CRM 2011的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to access leads (create new lead and get the list) in crm 2011 through the web services. I already made an app in c#/asp.net(it works) but now i have to do it in php and i'm stuck.

i尝试: https://code.google.com/p/php-dynamics- crm-2011 / ,但是它不起作用,因为它仅支持联合身份验证,并且挖掘了它的活动目录。

i try: https://code.google.com/p/php-dynamics-crm-2011/ but it doesn't work because it supports only Federation authentication and mine it's active directory.

我尝试与nusoap连接,但是它非常

I try to connect with nusoap but it's very confusing.

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

I generate classes of discovery service and organization service with wsdl2php: http://www.urdalen.no/wsdl2php/ but i don't know what to do with the classes.

有人提供了如何使用这些类的示例吗?

Someone has examples how to use these classes?

推荐答案

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

MSCRM 2013 and probably 2011 are using NTLM for authentication the websevices.

对于数据查询,您可以使用网址编码的FetchXML

For data query, you can use url encoded FetchXML

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

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

You can get the correct XML from CRM by exporting XML in Advanced search and execute the query with RetrieveMultiple method for example.

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

这篇关于PHP-使用Web服务访问Dynamics CRM 2011的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆