PHP SOAP Integration with MS Dynamics 2011/2013 (IFD)


PHP SOAP Integration with MS Dynamics 2011/2013 (IFD)

目前,我正在尝试连接PHP网站与MS Dynamics 2013。我发现下面的例子(https://github.com/rocketeer007/php-dynamics-crm-2011)连接到,但它不工作。

我提供了配置,但得到以下错误,即

string(576) "http://www.w3.org/2005/08/addressing/soap/faults:Sendera:InvalidSecurity 
An error occurred when verifying security for the message."

我找不到关于soap响应的更多信息。

这是我在请求中发送的更多信息,即

     **NOTE: For example purposes below I have changed the URLs**
    //Parameters values used in the below CURL
    $soapUrl = https://example.crmserver.com/adfs/services/trust/13/usernamemixed
    $headers = 'POST /adfs/services/trust/13/usernamemixed HTTP/1.1
     Host: adfs.crmserver.com
     Connection: Keep-Alive
     Content-type: application/soap+xml; charset=UTF-8
     Content-length: 1481'
     $content = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
    <a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue</a:Action>
    <a:ReplyTo>
        <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">https://adfs.crmserver.co.nz/adfs/services/trust/13/usernamemixed</a:To>
    <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
        <u:Timestamp u:Id="_0">
            <u:Created>2015-07-16T04:09:52.00Z</u:Created>
            <u:Expires>2015-07-16T04:10:52.00Z</u:Expires>
        </u:Timestamp>
        <o:UsernameToken u:Id="user">
            <o:Username>desktop'abc_service.mrl</o:Username>
            <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</o:Password>
        </o:UsernameToken>
    </o:Security>
</s:Header>
<s:Body>
    <trust:RequestSecurityToken xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
        <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
            <a:EndpointReference>
                <a:Address>https://dev2013.crm.crmserver.co.nz/XRMServices/2011/Discovery.svc</a:Address>
            </a:EndpointReference>
        </wsp:AppliesTo>
        <trust:RequestType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue</trust:RequestType>
    </trust:RequestSecurityToken>
</s:Body>

    // Request
    $cURLHandle = curl_init();
    curl_setopt($cURLHandle, CURLOPT_URL, $soapUrl);
    curl_setopt($cURLHandle, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($cURLHandle, CURLOPT_TIMEOUT, self::$connectorTimeout);
    curl_setopt($cURLHandle, CURLOPT_SSL_VERIFYPEER, TRUE);
    curl_setopt($cURLHandle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
    curl_setopt($cURLHandle, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($cURLHandle, CURLOPT_POST, 1);
    curl_setopt($cURLHandle, CURLOPT_POSTFIELDS, $content);
    curl_setopt($cURLHandle, CURLOPT_HEADER, false);
    curl_setopt($cURLHandle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    $responseXML = curl_exec($cURLHandle);
    if(curl_exec($cURLHandle) === false)
    {
         echo 'Curl error: ' . curl_error($ch);
    }
    else
    {
         echo "no error <br />";
         var_dump($responseXML);
    }

我试图看到错误,但得到以下即。没有错误

我被困住了,在网上找不到任何东西,因此,在这里发帖…

更多信息:当我尝试从命令行,即。curl -H "Authorization: Bearer" https://dev2013.crm.example.com/XRMServices/2011/Discovery.svc -v

然后,我得到以下输出,即

About to connect() to dev2013.crm.appserv.co.nz port 443 (#0)
*   Trying x.x.x.x... connected
* successfully set certificate verify locations:
*   CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using AES128-SHA
* Server certificate:
*  subject: C=AU; ST=Sydney; L=Sydney; O=Example Ltd; CN=*.crm.example.com
*        start date: 2015-06-24 00:00:00 GMT
*        expire date: 2017-08-22 23:59:59 GMT
*        subjectAltName: dev2013.crm.example.com matched
*        issuer: C=US; O=thawte, Inc.; CN=thawte SSL CA - G2
*        SSL certificate verify ok.
> GET /XRMServices/2011/Discovery.svc HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: dev2013.crm.example.com
> Accept: */*
> Authorization: Bearer
>
< HTTP/1.1 200 OK
< Connection: Keep-Alive
< Set-Cookie: ISAWPLB{11FDD9E3-24F0-455D-8590-436AF3F4D26D}={B0F3D377-6B32-45C6-A517-DA83209E8EA4}; HttpOnly; Path=/
< Content-Length: 3127
< Date: Thu, 16 Jul 2015 03:26:39 GMT
< Content-Type: text/html; charset=UTF-8
< Server: Microsoft-IIS/8.5
< Cache-Control: private
< X-AspNet-Version: 4.0.30319
< REQ_ID: 5b87d8d2-8b5e-4979-b090-7df14a3a1603
< Set-Cookie: ReqClientId=751fb9c2-ac10-478a-b933-2117420c660c; expires=Thu, 16-Jul-2065 03:26:39 GMT; path=/; secure; HttpOnly
< X-Powered-By: ASP.NET

这意味着使用上述发现服务器连接到CRM没有问题。

寻找关于错误的即时帮助和使用PHP SOAP web服务从CRM获得身份验证的最佳建议。

提前感谢。

欢呼,

Jason Lattimer有一个使用IFD的更新示例。

http://jlattimer.blogspot.com.au/2015/02/soap-only-authentication-using-php.html

乍一看似乎有一些不符之处。首先,你没有消息ID(应该在操作行下面)

<a:MessageID>urn:uuid:{A RANDOM GUID GOES HERE}</a:MessageID>

第二行是

<o:UsernameToken u:Id="user">

我也认为应该是GUID

<o:UsernameToken u:Id="{GUID GOES HERE}">

最后你看起来像是在指向发现服务,而我认为你应该指向组织服务。

Organization.svc

我自己没有做过任何PHP-IFD的东西,所以我建议去看看Jason的博客,把它和你的比较一下。

Campey,谢谢你的宝贵时间。DEV和LIVE服务器都在同一个时区,我发现DEV服务器的时区比LIVE服务器晚10分钟。

我纠正了DEV服务器上的时间,然后认证问题就解决了。

感谢大家花时间阅读这期杂志