Really hoping someone can help with this as I just can't seem to resolve this issue.
I am having great difficulty with getting the code below to work on my website.
The purpose of the script is to return car lengths based on a provided registration number.
The problem is when I move this over to my live environment the script simply won't work. Please can anyone suggest a possible resolution? I don't understand why It works absolutely fine in the development environment but when I attempt to run it on my main site I get the following error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://website.com/CarLengthChecker.asmx?WSDL' : failed to load external entity "https://website.com/CarLengthChecker.asmx?WSDL"
<?php
$carReg = "0000000";
try{
$opts = array(
'http'=>array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$client = new SoapClient ('https://wesite.com/CarLengthChecker.asmx?WSDL',
array('stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE));
$result = $client->GetVehicleDetails(array(
'VRM' => $carReg,
));
print_r($result);
}
catch(Exception $e){
echo $e->getMessage();
}
?>
I can access the WSDL address from a browser on the live server just not from the script.
I have checked the PHP settings on live and can confirm that both OpenSSL & SOAP
are enabled.
The resolution I found for this was to use the nusoap library (www.sourceforge.net/projects/nusoap). This problem may have been specific to our to live server environment but I would recommend attempting it if you are experiencing similar issues.
Related
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 ?
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:
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".
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.
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:
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.
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
I have check every configuration is perfect like, SOPA, CURL, XML, libxml in php.ini file. But I am getting issue. I don't know what is the issue. It's working on local machine but when i upload on server and check then it's not working. I am trying to integrate dynamic nav api using NTLMSoapClient but it's not working in server.
Please see Below Code
$product = new NTLMSoapClient(PRODUCT_URL);
/*$params_d = array('filter' => array(
),
'setSize' => 2);*/
$result = $product->ReadMultiple();
$productData = $result->ReadMultiple_Result->WebItems;
Please help me if you know any solution
This error message is really unspecific and could just mean that curl returned false, luckily you can use curl_error to find out what exactly went wrong. In my implementation it looked like this.
$this->buffer = curl_exec($this->ch);
if (curl_errno($this->ch)) {
$error = curl_error($this->ch);
throw new Exception('CURL error: ' . $error);
}
I am new to SOAP. Below code works fine in my local environment, my php version is php-5.3.3 and soap client version 1_1.
`
require_once "../app/Mage.php";
Mage::app();
$client = new SoapClient('https://mydomain/api/soap?wsdl&type=soap');
$session_1 = $client->__getFunctions();
echo '<pre>'; print_r($session_1);echo '</pre>';
$session = $client->login('user', 'password');
// If you don't need the session anymore
$client->endSession($session);
`
When I try to execute this code in server(php-5.3.29 and soap client 1_1),
I am getting an error as following
` Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from ..`
Then we tried the code with some changes in server as
require_once "../app/Mage.php";
Mage::app();
$client = new SoapClient('http://mydomain/api/soap?wsdl&type=soap', Array(
'location' => 'http://mydomain/api/soap?wsdl&type=soap',
'cache_wsdl' => WSDL_CACHE_NONE,
'soap_version' => SOAP_1_1));
var_dump($client);
$session = $client->login('user', 'password');
I got this error
Fatal error: Uncaught SoapFault exception: [VersionMismatch] Wrong Version in ..
Also when we tried curl http://mydomain/api/soap? wsdl&type=soap , it worked fine.
Can any one help on this?
Not really sure if this is a help to you, but as there's a difference in PHP versions between the local and server environments, I thought it might help.
There's a PHP bug that was fixed in 5.3.11 that caused me to get a Version Mismatch error when trying to connect to the Royal Mail Shipping API in OpenCart.
Here's details of the bug: https://bugs.php.net/bug.php?id=49853
Basically, the stream_context part of the http header is being ignored, and that contains the client ID and secret.
Contained within is a workaround:
ini_set('user_agent', 'PHP-SOAP/' . PHP_VERSION . "\r\n" . $str_auth_header);
where
$str_auth_header = "Authorization: Bearer ". $str_token;
$arr_context = array('http' =>array('header' => $str_auth_header));
$obj_context = stream_context_create($arr_context);
I am feebly trying to implement a stamps.com api interface into my platform. This is my first time using SOAP, I event had to recompile PHP to enable the libraries.
I'm moving along but now I'm having a problem. They support soap 1.1 and soap 1.2 requests, and when I run the following code:
$client = new SOAPClient(
'./SWSIM.wsdl',
array(
'trace' => 1
)
);
I get back a successful response from my request that comes after this.
However if I add the option to use soap 1.2 like this:
$client = new SOAPClient(
'./SWSIM.wsdl',
array(
'trace' => 1,
'soap_version' => SOAP_1_2
)
);
I get the following error:
There was an exception running the extensions specified in the config file. ---> Value cannot be null. Parameter name: input
This line is not actually throwing the exception. Its the following command that throws it, but removing the soap_version is what "fixes it". I would like to use soap 1.2 so naturally this is bugging me.
FTR The command I'm running is this:
$authData = array(
"Credentials" => array(
"IntegrationID" => "MYUID",
"Username" => "MYUSERNAME",
"Password" => "MYPASSWORD"
)
);
try {
$objectresult = $client->AuthenticateUser($authData);
} catch (Exception $e) {
echo "EXCEPTION: " . $e->getMessage();
print_r($e);
exit;
}
The WSDL file can be viewed here:
https://swsim.stamps.com/swsim/swsimv22.asmx?wsdl
I have also checked in with their developer support and they said:
"The message you are currently receiving is returned from whichever program you are designing your integration with. This has been commonly noted happening within Visual Basic where is creates a wrapper class that needs certain variables for the response. This could be similar to the behavior that you are experiencing. Please verify how your program language consumes a WSDL."
I also noticed that the __soapCall method excepts an "input headers" argument. I'm not entirely sure I should be / can even use that method in my code. I suppose I should just try and play with it.
Check your WSDL file. I was using the wrong one, and it appears you may be as well. Try this one: http://developer.stamps.com/developer/downloads/files/Stamps.com_SWSIM.wsdl
NOTE: The above is out of date. Contact stamps.com for the current wsdl!
I know this is an old thread, but here is an example class that should get anyone started with the stamps.com api in php https://github.com/aaronjsmith/stamps.com-php
The WSDL looks fine and it's the same input structure for both Soap versions. The problem is a bug somewhere at their end, you'll have to contact them to resolve.
I would also test it via a .NET app just to see if it behaves the same.
I am trying to use a function from SOAP, which will fetch details about a specific news item. The problem is that I don't get the expected results, just a a strange error. I am using the built-in SOAP client in PHP5.
My error is:
Fatal error: Uncaught SoapFault
exception: [Client] SOAP-ERROR:
Encoding: External reference
'https://newsclient.omxgroup.com/cdsPublic/viewDisclosure.action?disclosureId=379485&messageId=454590'
in
/home/********/public_html/********/updatenews3.php:15
My code is:
<?php
$login = '***';
$password = '***';
$client = new SoapClient(
'https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl',
array(
'login' => $login,
'password' => $password
));
$param = array('lastPublicationId' => 361825);
$result = $client->fetchNews($param);
?>
The error is the same for all lastPublicationId, where a result is found. It seems as if PHP is trying to load a link, which is found somewhere in the XML-reply (the URL, which is in the error message), and can't access it. Even though I have googled this a lot, I can't find any solution. The only thing I can find is that this seems to have been reported as a bug in a previous version of PHP, but the error refers to PHP 5.2.2 Since I'm using PHP 5.2.9, I'm thinking it can't be that. I'm suspecting the &-character to be the cause of this error?
The WSDL-file can be found here: https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl
Does somebody know this error, and know of any solution?
It's possible that the XML being returned by $client->fetchNews($param); isn't being escaped properly - there seems to be an unescaped & in the URL which is shown in the error message.
Best thing is probably to check exactly what XML is being returned, by turning on tracing and printing the last response:
$client = new SoapClient(
'https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl',
array(
'login' => $login,
'password' => $password,
'trace' => 1
));
$param = array('lastPublicationId' => 361825);
try {
$result = $client->fetchNews($param);
}
catch (SoapFault $sf) {
print '<pre>';
// print the exception
print_r($sf);
// print the XML response
print $client->__getLastResponse();
}
A workaround (if the server is returning invalid XML) is to use code similar to the above to catch the exception. You can then manually get at the XML returned (using __getLastResponse()), and clean it up yourself (e.g. using htmlenties or a regexp), before returning it and using it in the rest of your application.