禁止通过PHP Curl在Dynamics 365 AX上调用方法 [英] Forbidden to Call method on Dynamics 365 AX via PHP Curl

查看:69
本文介绍了禁止通过PHP Curl在Dynamics 365 AX上调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过PHP curl通过WSDL从Dynamics SOAP调用方法.

I am trying to call methods from dynamics SOAP through WSDL via PHP curl.

我从我的webapp和SOAPUI都收到此错误. 可能是什么问题呢?从具有相同凭据的.NET测试程序访问时,它可以正常工作.刚从PHP方面面临问题,说禁止使用1317代码.指定的帐户不存在

I get this error from both my webapp and SOAPUI. What could be the problem? It works fine when accessed from a .NET testing program with same credentials. Just facing problems from PHP side saying Forbidden with 1317 code. The specified account does not exist

我一直在尝试调用该方法,并遇到了不同的问题.我遇到的最后一个问题是此方法. 我以为是用户代理我更改了它,所以我使用了SOAPUI.一样. 我所知道的是,该用户已在Azure AD中注册,并且应该具有该应用程序的授权.

I've been trying to call the method and faced different issues last issue I faced is this one. I thought maybe user agent I changed it I used SOAPUI. same thing. What I know is the user is registered in Azure AD and should have authorization for the app.

POST是

POST /soap/services/servicemethodname?wsdl 
HTTP/1.1 
Host: domainname.sandbox.ax.dynamics.com 
Accept: text/xml 
Accept-Encoding: gzip,deflate 
Connection: Keep-Alive 
Content-type: text/xml 
User-Agent: Apache-HttpClient 
Authorization: Bearer longTokenString
Soapaction: "http://tempuri.org/webservice/method" 
Content-Length: 795 

响应是

 HTTP/1.1 500 Internal Server Error Cache-Control: private 
 Content-Type: text/xml; charset=utf-8 
 Server: Microsoft-IIS/10.0 
 Strict-Transport-Security: max-age=31536000; includeSubDomains 
 Set-Cookie: ASP.NET_SessionId=hghtgkuhlihkjg; path=/; secure; 
 HttpOnly Set-Cookie: 
 ms-dyn-csrftoken= someTokenSTring; path=/; secure 
 ms-dyn-fqhn: 
 ms-dyn-namespace: namespace 
 ms-dyn-tenant: tenantidstring 
 ms-dyn-role: 
 ms-dyn-aid: aidString 
 X-Powered-By: ASP.NET 
 X-Content-Type-Options: nosniff 
 X-Frame-Options: SAMEORIGIN 
 p3p: CP="No P3P policy defined. Read the Microsoft privacy statement at https://go.microsoft.com/fwlink/?LinkId=271135" 
 Strict-Transport-Security: max-age=31536000; 
 includeSubDomains Date: Thu, 01 Aug 2019 19:24:52 GMT Content-Length: 1112 
 a:ForbiddenForbidden1317System.ComponentModel.Win32ExceptionThe specified account does not exist0-2147467259

我需要能够正确调用该方法并获取其发送的值.

I need to be able to call the method without errors and get the values it sends.

我的php代码

$requestBody = trim('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://schemas.microsoft.com/dynamics/2013/01/datacontracts" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tem="http://tempuri.org">
   <soapenv:Header>
      <dat:CallContext>
         <dat:Company>company</dat:Company>
         <dat:Language>en-us</dat:Language>
         <dat:MessageId>?</dat:MessageId>
         <dat:PartitionKey>12345667</dat:PartitionKey>
      </dat:CallContext>
   </soapenv:Header>
   <soapenv:Body>
      <m:getMethod xmlns:m="http://tempuri.org/webService/getMethod">
         <m:parameterName soap:mustUnderstand="1">12345</m:parameterName>
      </m:getMethod>
   </soapenv:Body>
</soapenv:Envelope>
            ');

    $soapAction = 'SOAPAction: http://tempuri.org/webService/getMethod';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, 
            array(  'Accept:text/xml',
                    'Accept-Encoding: gzip,deflate',
                    'Connection: Keep-Alive',
                    'Content-type: text/xml; charset=utf-8',
                    'Cache-Control: no-cache',
                    'Pragma: no-cache',
                    'Authorization: Bearer longstringToken',
                    'SOAPAction: http://tempuri.org/webService/getMethod'
                ));
 if ($postData != '') {
            curl_setopt($ch, CURLOPT_POSTFIELDS,$postData);             
        }
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
// By default https does not work for CURL.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt ($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
// Set the option to recieve the response back as string.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$odataURL = 'https://domainname.sandbox.ax.dynamics.com/soap/services/webService'; 
curl_setopt($ch, CURLOPT_URL, $odataURL);
// enable string response
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);

curl_setopt($ch, CURLOPT_POST, true);   

curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
// Mark as Post request
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
// $output contains the output string
$output = curl_exec($ch);

推荐答案

好的,所以终于找到了解决方案. 它有助于阅读有关您使用的类和所使用的不同系统的文档.就我而言,我试图将我的应用程序与Microsoft Dynamics 365 ax集成在一起,因此我也必须阅读有关内容.

Ok so finally found a solution. It helps to read documentations on the classes you use and different systems used. In my case i was trying to integrate my app with microsoft dynamics 365 ax, so i had to read up on that too.

我阅读了很多文档,其中一些文档与不同的动态服务有关,但是

I read a lot of documents some were related to different dynamics service but this one helped most

并且由于soap服务需要授权标头,因为它们使用的是Windows身份验证,所以我们需要从oAuth链接中获取令牌.

And since the soap service needed Authorization Header, because they were using Windows authentication, we needed to get the token from oAuth link.

https://login.windows.net/ $ tenantDomainName/oauth2/token

https://login.windows.net/$tenantDomainName/oauth2/token

PS:我从 github 知道的oauth2链接 PHPConsoleApplication

PS: the oauth2 link i knew about it from github PHPConsoleApplication

我使用PHP CURL获取授权令牌,然后使用PHP的SoapClient类创建了客户端.

I used PHP CURL to get my authorization Token and then created a client using PHP's SoapClient Class.

确保像这样在标头中添加授权令牌:

Make sure you add the authorization token in the header like so:

$arrayOpt = array(    
'stream_context'  => stream_context_create(
                            array('http' =>'Authorization: Bearer tokenString')
 ));

$client = new SoapClient($wsdl, $arrayOpt);

$response = $client->serviceMethod($parameters);

var_dump($response);

您将获得该方法的值.

这篇关于禁止通过PHP Curl在Dynamics 365 AX上调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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