PHP - Cannot get SOAP server to work - php

I have written a very simple SOAP Server to check access to the server but I'm getting an error.
The server is a brand new VM of Windows Server 2008R2 (which I installed today to check this) I then installed WAMP which is working correctly. I think the issue is more of a configuration one but I'm no expert from here so need some help finding it.
I have enabled SOAP in WAMP. The WSDL is fine, I have checked it on a hosted server and it works as expected along with the server and client php files.
The error received at the client:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
Couldn't load from './Soaptest.wsdl' : failed to load external entity "./Soaptest.wsdl" in
C:\wamp\www\Connector\Testing\c20\c20simpleClient.php:7
Stack trace: #0 C:\wamp\www\Connector\Testing\c20\c20simpleClient.php(7):
SoapClient->SoapClient('./c20simpleSoap...') #1 {main} thrown in
C:\wamp\www\Connector\Testing\c20\c20simpleClient.php on line 7
The Soap Server:
function Test(){
return true;
}
$server = new SoapServer("Soaptest.wsdl");
$server->addFunction("Test");
$server->handle();
The client (Line 6+):
$url = "./Soaptest.wsdl";
$client = new SoapClient($url);
echo "client created<br>";
$result = $client->Test();
echo "<hr>Method Test: <pre>".(string)$result."</pre>";
Aside from enabling soap in the php config, is there anything I need to do in Apache or php to enable SOAP?

Related

Getting SOAP error when parsing WSDL from an API when the website hosting has been changed

Switched hosting and I have been encountering a SOAP error. The PHP version I am running is 7.3 and the previous hosting was 7.2. The URL that the soap client is trying to access is open and allows anyone to access it. SOAP has been enabled on cPanel.
<?php
try{
$soapclient = new SoapClient('http://url/Schedule_service.asmx?re_Status&WSDL');
$param = array('TheatreId'=>101,'FilmId'=>0);
$response = $soapclient->FnSchedule_Film_Theatre_Status($param);
$coming_result = json_decode(json_encode($response),true);
}catch(Exception $e){
echo $e->getMessage();
}
?>
The error message is displayed on the website is, where URL is the soap client url:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://url' failed to load external entity 'http://url'

PHP EWS - Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized in

I am using https://github.com/jamesiarmes/php-ews library to connect to our Microsft Exchange Server 2010 SP3 but I am getting this error: Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized in
I am using the example provided under: /examples/message/create.php
and the error is triggered on this line:
index.php
$response = $client->CreateItem($request);
Client.php
$response = $this->soap->{$operation}($request);
When I try to access the wsdl file from the browser it works fine and after authentication, I can see all the options under Services.wsdl .
What do you think the problem is?
Is there some settings that I need to enable on Microsoft Exchange in order to use the SOAP services?

PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'Couldn't resolve host 'accounts.google.com'

I have used google api for Analytics service. First 3 days from this implementation, it worked fine, but from 30th Apr 2015. suddenly it got trouble with the following error. I have executed this php program through a web page access by using Apache cron. When I access to the page, it return 500 error and
PHP Error log;
PHP Fatal error: Uncaught exception 'Google_IO_Exception' with
message 'Couldn't resolve host 'accounts.google.com'' in
/var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/IO/Curl.php:115\nStack
trace:\n#0
/var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/IO/Abstract.php(136):
Google_IO_Curl->executeRequest(Object(Google_Http_Request))\n#1
/var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/Auth/OAuth2.php(336):
Google_IO_Abstract->makeRequest(Object(Google_Http_Request))\n#2
/var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/Auth/OAuth2.php(308):
Google_Auth_OAuth2->refreshTokenRequest(Array)\n#3
/var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/get-pageview.php(52):
Google_Auth_OAuth2->refreshTokenWithAssertion(Object(Google_Auth_AssertionCredentials))\n#4
/var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/get-pageview.ph
in
/var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/src/Google/IO/Curl.php
on line 115
My code to connect google api;
require_once dirname(__FILE__) . '/src/Google/autoload.php';
$client_email = 'xxx#developer.gserviceaccount.com';
$view_id = "xxx";
$private_key = #file_get_contents(dirname(__FILE__) . '/xxx.p12');
$client = new Google_Client();
$scopes = array("https://www.googleapis.com/auth/analytics.readonly");
if(isset($_SESSION["service_token"])){
$client->setAccessToken($_SESSION["service_token"]);
}
$credentials = new Google_Auth_AssertionCredentials($client_email,$scopes,$private_key);
$client->setAssertionCredentials($credentials);
if($client->getAuth()->isAccessTokenExpired()){
$client->getAuth()->refreshTokenWithAssertion($credentials);
}
$_SESSION["service_token"] = $client->getAccessToken();
...
I used this library. I have updated this to the latest in 3 days ago.
I have found similar error posts in stack overflow, but most are caused from server connection problems to 'accounts.google.com', but my server could connect it before. Also I checked host/nslookup too;
# nslookup accounts.google.com
Server: 210.157.3.4
Address: 210.157.3.4#53
Non-authoritative answer:
accounts.google.com canonical name = accounts.l.google.com.
Name: accounts.l.google.com
Address: 216.58.220.173
# host accounts.google.com
accounts.google.com is an alias for accounts.l.google.com.
accounts.l.google.com has address 216.58.220.173
accounts.l.google.com has IPv6 address 2404:6800:4004:812::200d
My most concern is that why suddenly error occurred? even though I have not changed any code /library files where I got success in API connection before.
Also I dubious about token problem too, but in my case only 2 or 3 machine has connected api, so it must not be limit of token.
I also checked my server ntp but it worked correct in my server.
I hope anyone had same issues know how to fix it. Thank you always.
--addition 20150505--
Yesterday I tried not through webpage but through command script to access php file, then api worked. Still not get why webpage access suddenly failed, but my problem itself seem to be solved.
cron before
wget http://example.com/analytics-api?f=1
cron after
php /var/www/html/components/com_jumi/files/analytics/google-api-php-client-master/get-pageview.php -f1
I had same problem today so
I just disable the firewall and it worked for me
I am using avg antivirus

php WSDL (SOAP) client

I have a problem co communicate with SOAP service in php:
My code for client:
$url = "https://XXXX.com/DataService.svc?singleWsdl";
$client = new SoapClient($url);
var_dump($client->__getFunctions()); // ExportScheduleData(ExportScheduleData $parameters)
$aclient->ExportScheduleData(array());
I got:
Uncaught SoapFault exception: [HTTP] Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.
change soap version to 1.2:
$client = new SoapClient($url, array('soap_version' => SOAP_1_2));
And request could not be completed: when I refresh page it still in loaging state - any errors or so.
===== update =====
Looks like service use WS-Security. They provide certificate file, but:
Warning: SoapClient::SoapClient(): Unable to set local cert chain file `C:\xampp\htdocs\workspace\sandbox.dev\public\sandbox.cer'; Check that your cafile/capath settings include details of your certificate and its issuer in C:\xampp\htdocs\workspace\sandbox.dev\public\sandbox.php on line 34
Resolved.
Write a Java application for ws-secutity check and and query java app from php script. I use java tcp server.

SOAP: Fatal Error .. Could not connect to host

I've tried everything I can think of to no avail, and hope you can help.
I've taken on a site from another web dev, so am working on existing code.
The code works on my own development server (debian VM on my Win7 machine), but not on the live server (WHM/cPanel admin'd REDHAT Enterprise 5.4 x86_64 standard).
I get the following error after the call to $BHclient->startSession:
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /home/aap3r/public_html/soap_test.php:60
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://api.bul...', '', 1, 0)
#1 /home/aap3r/public_html/soap_test.php(60): SoapClient->__call('startSession', Array)
#2 /home/aap3r/public_html/soap_test.php(60): SoapClient->startSession(Object(stdClass))
#3 {main}
thrown in /home/aap3r/public_html/soap_test.php on line 60
The WDSL file is downloaded okay (though it appears to have the wrong mime-type).
Since the exact same test code works on one server but not another I thought it was a firewall issue, but the host denies it.
The relevant code:
$url = "http://api.bullhornstaffing.com/webservices-2.0/?wsdl";
ini_set('soap.wsdl_cache_enabled',1);
ini_set('soap.wsdl_cache_ttl',1);
$username = "xxx";
$password = "xxx";
$apiKey = "xxxx";
$session_request = new stdClass();
$session_request->username = $username;
$session_request->password = $password;
$session_request->apiKey = $apiKey;
$BHclient = new SoapClient($url, array("trace" => true, "exception" => false));
$API_session = $BHclient->startSession($session_request);
print_r($API_session);
phpinfo confirms that SOAP is installed, and I've tried the various implementation/installation methods presented in the control panels.
I've updated to PHP Version 5.3.27 and Apache to 2.2.25.
Any help will be hugely appreciated.
Update: I've found a workaround. For whatever reason the production server couldn't connect to HTTP*S*, so I copied and rehosted the WDSL file after manually editing it to replace the protocol.
I would record the network traffic with tcpdump:
tcpdump -s65535 -iYOUR_INTERFACE -w soap.pcap
You can analyze the traffic (soap.pcap) using wireshark.

Categories