1

I am connecting to dynamics 365. It used to work perfectly, i curl to get the token then i use it as an authorization header along with php soapclient and it works, i connect i create a client and i can call my methods.

All of a sudden it decided not to work, and where it used to connect as SOAP 1.1 now it enforced SOAP 1.2 After changing from SOAP 1.1 to SOAP 1.2 ( because I got the error of binding mismatch where it said expecting application/soap+xml and text/xml was found ) So I changed versions and that error disappeared and got replaced with ERROR Fetching HTTP Headers.

That error got stuck for the longest time, people suggested to increase timeout but i put it as high as 500 800 5000 all the same.

Then all of a sudden, it started giving me SOAP ERROR Parsing schema element already defined. I did not change my code, i played for awhile with the headers but to no avail, I even removed the authorization header just to see what is going on and that did nothing i kept getting the same error.

SOAP-ERROR: Parsing Schema: element 'http://schemas.datacontract.org/2004/07/Microsoft.Dynamics.Ax.Xpp:XppObjectBase' already defined [string:Exception:private]

everytime I try to connect I get different kind of parsing schema error even though i am not changing anything in my code:

SOAP-ERROR: Parsing Schema: element 'http://schemas.microsoft.com/2003/10/Serialization/:anyType' already defined [string:Exception:private]

and another

SOAP-ERROR: Parsing Schema: element 'http://schemas.datacontract.org/2004/07/Microsoft.Dynamics.AX.KernelInterop:ProxyBase' already defined [string:Exception:private] 

and then sometimes it does get through for a second but with fetching http header error again..

so i can not create a client instance anymore now.. where before i was able to create a client instance but i get an error when I call the method of "Error Fetching HTTP Headers"

something is definitely not stable because my errors are not one.

now some stated the wsdl could be faulty, but this is microsoft and the person i am in contact keeps saying he can not doing anything about it.

Help is this a PHP problem or a dynamics problem or wsdl custom made problem .

And how to solve this.

Thank you.

UPDATE

I'm sorry I mentioned earlier it is Dynamics AX , it turns out it is Dynamics 365 D365. I will keep dynamics ax tag in case it helps someone who needs the solutions provided.

UPDATE Following is the connection code I am using:

function getAuthenticationHeader()
{
   //Each variable has the values for our server
   //resource
   $appResource = urlencode($appADResource);
   //clientID
   $appClientID = urlencode($appADClientId);
   //appSecret
   $appSecret = urlencode($appADSecret);
   //username
   $appUserID = urlencode($appUserID);
   // Password
   $appUserPassword = urlencode($password);

   // Construct the body for the STS request
   $authenticationRequestBody =  'resource='.$appResource.'&client_id='.$appClientID.'&client_secret='.$appSecret.'&grant_type=password&username='.$appUserID.'&password='.$appUserPassword.'&scope=openid';

   //Using curl to post the information to STS and get back the authentication response    
   $ch = curl_init();
   // set url 
   $stsUrl = 'https://login.microsoftonline.com/'.$appTenantId.'/oauth2/token';        

   curl_setopt($ch, CURLOPT_URL, $stsUrl); 
   // Get the response back as a string 
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

   // Set the parameters for the request
   curl_setopt($ch, CURLOPT_POSTFIELDS,  $authenticationRequestBody);

   // By default, HTTPS does not work with curl.
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   // read the output from the post request
   $output = curl_exec($ch);         
   // close curl resource to free up system resources
   curl_close($ch);      
   // decode the response from sts using json decoder
   $tokenOutput = json_decode($output);

   return $tokenOutput->{'token_type'}.' '.$tokenOutput->{'access_token'};
}
try
{
    //WSDL Link
    $url = "https://urlToOurServer/services/webservice?wsdl";

    $authorizationToken = getAuthenticationHeader();
    $context = stream_context_create(array(
                'ssl'   => array(
                    'verify_peer'       =>  false, 
                    'verify_peer_name'  =>  false,
                    'allow_self_signed' =>  true
                ),
                'https' => array(
                    'curl_verify_ssl_peer'  => false,
                    'curl_verify_ssl_host'  => false
                    ),              
                'http'  => array(
                    'header'    =>'Authorization: '.$authorizationToken         
                    )
    )); 

    //Create array of Soap Options
    $arrOpt = array(
    "soap_version"      => SOAP_1_2,
    "cache_wsdl"        => WSDL_CACHE_NONE,
    "exceptions"        => true,
    'trace'             => true,
    'encoding'          => 'UTF-8',
    'stream_context'    => $context 
    );
}catch(Exception  $e)
{
    print_r($e);
}

I also found this in my wsdl

<sp:IssuedToken sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<sp:RequestSecurityTokenTemplate>
<trust:TokenType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0
</trust:TokenType>
<trust:KeyType xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearer
</trust:KeyType>
</sp:RequestSecurityTokenTemplate>
<wsp:Policy>
<sp:RequireInternalReference/>

How can I connect to SAML for Token ?

2 Answers2

3

If everything is pretty much the same, but it's not working, the first thing to do is rule out the most basic AX issues. These may not solve your issue but will be a good first step.

now some stated the wsdl could be faulty, but this is microsoft and the person i am in contact keeps saying he can not doing anything about it.

Whomever that person is, you need to confirm they've done the following:

  1. Confirm the environment and specifically the CIL is fully compiled. Do a full AXBuild and a full CIL to be sure during non-business hours and ensure the output is good. It's basically saying "recompile everything".

  2. Refresh the WCF configuration in the client configuration you are using to connect to AX. This client configuration may be a *.axc file or it may just be the active one. Also refresh the business connector WCF. This is separate and may be what you are using to connect to AX. This is what most people are talking about.

Here's a little article that talks about creating a configuration, but I'll discuss below.

An AX client configuration ultimately is a bunch of text. It's either stored in an .axc file or stored in the registry in a few locations. The Business Connector client config may be the one that is getting missed in your scenario.

If you follow the link above and create a new .axc configuration file and ensure you've clicked "Refresh Configuration" before exporting, when you open the file up in Notepad, you'll see wcfconfig and a bunch of XML following it. That XML is what you're trying to get updated. Creating a new AXC here is just an exercise to help you understand what it is. You can delete the file after you're done looking.

enter image description here

Now, you've basically created a specific configuration file, but that doesn't mean anything is using it. If you call AX32.exe it will default to the one that is loaded in that config screen. Using a file is a way to very specifically choose one. Your code is probably using a specific AXC somewhere that needs either replaced or refreshed OR it's using one that's saved in this window:

enter image description here

It is very likely it is using one of the two that are saved in that configuration window. When you refresh in that window, it ultimately saves the WCF XML in the windows registry on the machine that is hosting the client and/or the AOS in subfolders in HKLM\SOFTWARE\Microsoft\Dynamics\6.0\Configuration. The key(s) is wcfconfig paired with wcfconfigversionid, which just stores a GUID to see if it's up-to-date.

When I say two, I mean most people don't even bother to look at the Business Connector AXC. It's what is highlighted in yellow in my image, and you need to specifically choose and refresh it. This could be important for you. In my image, I do not have it chosen. You need to drop the menu down and choose it.

On a dev machine, you can just clear both of those keys and refresh and you should see whatever configuration you're working on update.

This is a long post, but it's important to rule this part out first. If you have someone who's reasonably experienced administering AX they should know how to ensure these are refreshed.

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • 2
    Regarding new CIL compile: Make sure to delete the XppIL folder first to ensure a clean build (see [How to force complete CIL recreation in MS Dynamics AX 2012](https://cloudblogs.microsoft.com/dynamics365/no-audience/2014/06/22/how-to-force-complete-cil-recreation-in-ms-dynamics-ax-2012/). It also doesn't hurt to do a normal compile first. – FH-Inway Jan 21 '20 at 16:45
  • Thank you for your help everyone, but I just received a note that it is Dynamics 365 and not dynamics AX. any help is appreciated. – Sadeem M.K. Jan 22 '20 at 07:59
0

Since you're saying this is not Dynamics AX, but one of the Dynamics 365 versions. The AX version used to be called Dynamics 365 for Finance and Operations Enterprise Edition but they've changed the licensing/naming again, so I don't even know what it's technically called. Most people call it Dynamics 365 for Operations or some variant.

Either way, you should test the service following the below method. We would need to see more information about the service details and call, so following the below is most likely best.

https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/third-party-service-test

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • According to the new licensing, "AX" is being licensed under multiple names. So while we see a single AOT from a developer/technical perspective, a customer could purchase licenses for Dynamics 365 for Finance AND/OR Dynamics 365 for Supply Chain Management. And those licenses would unlock separate modules of the same wider application (cf https://dynamics.microsoft.com/en-us/pricing/#Finance) – rjv Jan 22 '20 at 17:19
  • @rjv so what are people calling it now? More specifically when googling `x++` issues or putting tags on stackoverflow? I've continued calling it D365 for Operations. – Alex Kwitny Jan 22 '20 at 17:37
  • Sales people edit:and executives* will use the terms I linked, but for the technical or consultant community I'm not entirely sure. I wish they would come up with a name for the overarching AOS-based product line for search term purposes and ease of communication. I use D365FO / for Operations / Finance and Operations interchangeably. When googling I'll use a combination of "x++", "axapta", "d365" etc... you get the point. It's annoying. – rjv Jan 22 '20 at 18:12
  • @rjv I completely agree. It has been driving me insane since `Rainer` or `AX7`. As a technical person, I'm sometimes at a loss to say "Yes I know D365 for " when it's a bunch of the same. – Alex Kwitny Jan 22 '20 at 18:25
  • Hi, The connection used to get established a month ago, just recently the services got switched to SOAP 1.2 and i started having those errors. What details you need to know? I'll update with my codes – Sadeem M.K. Jan 23 '20 at 07:48