FileMaker XML Web Publishing XML error - php

$FM_CONNECT = array(
'DB_FILE' => 'webaccess'
);
require_once "__app/dbConnect/FM.php";
require_once "__app/environmentSettings/environmentSettings.php";
$layout = 'webAccess';
$findCommand =& $fm->newFindCommand($layout);
$findCommand->addFindCriterion('AccountName', $_POST['username']);
$result = $findCommand->execute();
if(FileMaker::isError($result)){
FMExit(array(
'code' => 1,
'mes' => $result->getMessage()
));
}
$records = $result->getRecords();
When I try send some request to FileMaker server it return.
"XML error: Not well-formed (invalid token) at line 1"
I haven't change the code for a few weeks and I didn't see this error before.
Has anyone else experienced something like this?

This looks like FileMaker php api. If it is the case, you are missing the connection. If you just omitted the connection code from your code (since you get the error from the server), look at your request and check that XML is well formed. I can't check the request as you did not post it.

Make sure the web publishing engine is started and working. I faced this problem already and in my case the WPE was stopped suddenly. I started the WPE from the admin console and it was fine.

Related

PHP SOAP-ERROR: Parsing Schema: element already defined When Connecting to D365 WSDL

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

click2mail molpro api Illegal character exception only when in Google App Engine in production

I'm having a problem with my GAE instance (php55). My app is interacting with the api at http://click2mail.com/ and my code works just fine when I run my GAE on localhost, but click2mail is throwing an error when I run it from my GAE in production. They are producing a large stack trace and the root cause error in the trace is:
WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 5))
at [row,col {unknown-source}]: [1,213]
Their api is xml based, so I produce an xml string (of mailing addresses) and POST it to their api endpoint. I've contacted them and provided them with the xml I'm uploading and they can't find anything wrong with it and it uploads for them just fine.
I've done some exhaustive testing today to figure out the problem.
I set up a new Google App Engine instance so that I could isolate it from the rest of my app and try to get a minimal environment. I put together a simple test page so I could run it side-by-side on localhost and in the Google Cloud on GAE.
I verified the error still existed when I tried to upload 3000 addresses in Google's Cloud and still works when I do it from localhost.
Then I split the dataset in two (1500 and 1500) and tried each of them to see if one of them would work. Both worked on local, both failed in Google's Cloud.
I tried splitting it into 4 (750 each). All worked on local. All failed in Google's Cloud.
Then I tried uploading just a single address, the first address. Worked on local, failed on Google's Cloud.
Then I tried uploading a single address again, but the last address (just in case). Worked on local, failed on Google's Cloud.
I've tried to find anything that might be different from localhost GAE to production GAE. The code was using SimpleXMLElement to produce the xml and I thought maybe production GAE had a different implementation or something (much like ImageMagick works differently from localhost to production), so I tried updating the code to manually produce the XML instead of using SimpleXMLElement. Unfortunately, it worked on localhost but still failed in Google's Cloud.
Something is different about production GAE and is interfering with my app. It doesn't appear to be a problem in my code nor on click2mail's side, so I really need your help.
Here is an example of one of the xml api uploads I did where I only included a single address (but I've changed the address for privacy):
<?xml version="1.0"?>
<addressList>
<addressListName>test list one address time 1489112489</addressListName>
<addressMappingId>XXXXXX</addressMappingId>
<addresses>
<address>
<seller_id>XXXXXX</seller_id>
<due_date>2017-03-03</due_date>
<id>110</id>
<num>1</num>
<c_id>34</c_id>
<title>XXXXXX</title>
<first_name>XXXXXX</first_name>
<last_name>XXXXXX</last_name>
<address>XXXXXX XXXXXX Ave</address>
<city>XXXXXX</city>
<state>CA</state>
<zip>XXXXXX</zip>
<o1></o1>
<o2></o2>
<o3></o3>
<mail_address>XXXXXX XXXXXX Ave</mail_address>
<mail_city>XXXXXX</mail_city>
<mail_state>CA</mail_state>
<mail_zip>XXXXXX</mail_zip>
<phone1></phone1>
<manager_id>1</manager_id>
<delivery_type_id>8</delivery_type_id>
<carrier>click2mail</carrier>
<cost>0.4220</cost>
<weight>0.0000</weight>
<offer_exp>Friday, March 24, 2017</offer_exp>
<mailer_tracking>XXXXXX</mailer_tracking>
</address>
</addresses>
</addressList>
I even saved the xml to a file in Google Storage, downloaded it, and wrote some Java to check it character by character to see if it had any weird control characters in it. The only ctrl chars in it were linefeeds (\n).
As I said, the following code works just fine on localhost GAE, but click2mail throws an exception when I run it in production GAE.
$xml = new SimpleXMLElement('<addressList/>');
$xml->addChild('addressListName', $listname);
$xml->addChild('addressMappingId', $mappingid);
$addresses = $xml->addChild('addresses');
foreach($addresslistarray as $row) {
$address = $addresses->addChild('address');
foreach($fieldnames as $field) {
$value = '';
if ($row[$field] != null) {
$value = htmlspecialchars($row[$field]);
}
$address->addChild($field, $value);
}
}
$xmlstring = $xml->asXML();
$url = c2m_endpoint('addressLists'); // just builds the api url
$response = c2m_httppost($url, $xmlstring);
function c2m_httppost($url, $content) {
$client = new GuzzleHttp\Client(['verify'=>'ca-bundle.crt']);
$config = [
'auth' => [c2m_username(), c2m_password()],
'body' => $content,
'headers' => [
'Content-Type' => 'application/xml',
]
];
try {
$response = $client->request('POST', $url, $config);
$result = (string)$response->getBody();
return c2m_xml_to_map($result);
} catch (GuzzleHttp\Exception\ServerException $e) {
error_log("URL: $url");
error_log("REQUEST: ".GuzzleHttp\Psr7\str($e->getRequest())."\n\n");
if ($e->hasResponse()) {
$mesg = "RESPONSE: ".GuzzleHttp\Psr7\str($e->getResponse())."\n\n";
print($mesg);
error_log($mesg);
}
return null;
}
}
I've exhausted all of my ideas. Do you have any ideas why this would work on localhost but fail in production on GAE?

Using PHP SOAP client in non-WSDL mode

I am working on an api for a client. I have received the following information:
API Url: http://xyz-crm.example/WebAPI/Custom/project_name/XML/
Username: foobar
password: spameggs
I need to configure the PHP SOAP client for the same in non-WSDL mode. I have written the following but it does not seem to work:
$wsdl = null;
$options = array(
'uri' => 'http://xyz-crm.example/WebAPI/Custom/project_name/XML/',
'location' => 'http://xyz-crm.exmaple.com/WebAPI/Custom/project_name/XML/',
'login' => 'foobar',
'password' => 'spameggs'
);
$client = new SoapCLient($wsdl, $options);
I just want to make a successful ping to the api at first. See if things are working fine. What am I doing wrong here?
Update 1
I made the following changes:
$wsdl = null;
$options = array(
'uri' => "http://xyz-crm.example/WebAPI/Custom/project_name/XML/",
'location' => "http://xyz-crm.example/",
'Username' => "foobar",
'Password' => "spameggs",
'soap_version' => '1.2'
);
$client = new SoapClient($wsdl, $options);
$client = $client->getListings();
I get the error: looks like we got no XML document
[Edit by me, hakre: This update was done as feedback to answer #1. It changes the location option using a shortened URL (reason not given by OP) and it adds the soap_version option (as suggested in answer #1, but not as constant but as string (containing an invalid value), so there should be no wonder this creates an error, a correct option value is given in answer #1 (the SOAP_1_1 constant) and by intention, the correct value would be the SOAP_1_2 constant for this example). Error message as commented by OP was "SOAP Fault: Wrong version."]
Update 2
I tried the following but it still fails:
$listing = $client->getListings();
$request = $client->__getLastRequest();
The execution stops at the first line itself without ever going to the second one.
[Edit by me, hakre: As review has shown wrong configuration options in Update 1 already which are not addressed in Update 2 it would be a miracle if it still wouldn't fail. The execution stops because an Exception is thrown and no error/exception handling is done]
Die URI or file ending does not matter, it could even be .jpg, there is no default.
Have a look at similiar questions: Does this SOAP Fault mean what I think it means?
It would be helpful if you put the error message into the question, aswell as the XML output of your request.
try setting the SOAP Version in the array of your SoapClient instance to one of the constants (try different ones):
new SoapClient($url, array("soap_version" => SOAP_1_1,.......
or SOAP_1_2 ...
To debug the XML try the answer from Inspect XML created by PHP SoapClient call before/without sending the request
The error message of your updated question does not look like it coming from PHP, looks more like an answer from the webservice, means your request is actually working.

Soap request failing. Server or code issue?

I'm trying to setup a data request for a site, but, am running into a problem when trying to pull the data.
I tested the url and credentials using http://www.soapclient.com/soaptest.html and it works perfectly so I know the service is up and the correct credentials are being entered, but, when using the code below, I'm given the following error;
Fatal error: Uncaught SoapFault exception: [Invalid Login] in...
The full code (except generalized URL) that I'm using to make the request is;
<?php
$client2 = new SoapClient("http://www.example.com/api/soap.php?wsdl", array('trace'=> true));
$results2 = $client2->boxInfo(array(
"customer" => 'XBLK',
"size" => "four",
"price" => "twenty"));
echo "<pre>";
var_dump($client2-> __getLastRequestHeaders());
var_dump($client2-> __getLastRequest());
var_dump($client2-> __getLastResponseHeaders());
var_dump($client2-> __getLastResponse());
var_dump($results2);
echo "</pre>";
?>
As I'm new to these calls, I'm not sure if I missed something with the SOAP installation when I updated php (I verified it's installed and enabled) or if I've just been staring at the code so long that I'm simply missing something obvious.
It's a client issue if it works elsewhere. Try using an object to hold the parameters instead of an array:
$params = new stdClass();
$params->customer = 'XBLK';
$params->size = 'four';
$params->price = 'twenty';
$results2 = $client2->boxInfo($params);

Soap 1.2 not working with stamps.com

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.

Categories