I am implementing a PHP SOAP server using a third party wsdl. The included xsd has an reference to the external schema as bellow:
<xsd:import schemaLocation="http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd" namespace="http://www.w3.org/2000/09/xmldsig"/>
The SoapClient with bellow code works perfectly:
$options = array();
$options['features'] = 1;
$options['trace'] = 1;
$options['connection_timeout'] = 2000;
$options['exceptions'] = 1;
$options['soap_version'] = SOAP_1_1;
$options['encoding'] = 'UTF-8';
$options["user_agent"] = 'php-file_get_contents/'.phpversion();
$clent = new SoapClient( $wsdl, $options);
But not the SoapServer
$options = array();
$options['features'] = 1;
$options['trace'] = 1;
$options['connection_timeout'] = 2000;
$options['exceptions'] = 1;
$options['soap_version'] = SOAP_1_1;
$options['encoding'] = 'UTF-8';
$server = new SoapServer($wsdl, $options);
Which trows the following error
SoapServer::SoapServer("http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd"): failed to open stream: HTTP request failed! HTTP/1.0 500 Server Error\r\n in ..../index.php on line 54
PHP Warning: SoapServer::SoapServer(): I/O warning : failed to load external entity "http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd" in ..../index.php on line 54
PHP Fatal error: SOAP-ERROR: Parsing Schema: can't import schema from 'http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd' in .../index.php on line 54
The SoapClient was also throwing the same error, but which is resolved after adding the "user_agent" option.
I don't see a "user_agent" option for SoapServer.
am I missing something here?
I am able to access the url: http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd and able to download the xsd file
Edited: Added the actual xsd link.
Related
Basically when I try to connect to a HTTPS based SOAP web service I receive the error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://webservice.sample.com/ws/' : failed to load external entity "https://webservice.sample.com/ws/"
I have tried the answers to this error previous and most of them either apply to Windows based servers or don't work in my case.
I am doing this connection on a Linux based server. The code that I am using is
<?php
include('File/X509.php');
error_reporting( E_ALL );
ini_set( "display_errors", 1 );
$x509 = new File_X509();
$certfile = file_get_contents('/path/to/cert/file');
$cert = $x509->loadX509($certfile);
$openedcert = openssl_x509_parse($certfile);
$security_requests_array = array();
try {
$client = new SoapClient('webserviceendpoint', ['trace' => true, 'cache_wsdl' => WSDL_CACHE_MEMORY,'local_cert'=>'/path/to/cert/file']);
$header = new SoapHeader($security_requests_array);
$client->__setSoapHeaders($header);
print_r($client->__getLastResponse());
} catch (Exception $ex) {
var_dump($ex->faultcode,$ex->faultstring,$ex->faultactor,$ex->headerfault);
}
?>
I am new to HTTPS based SOAP webservices. So if there is any other information you would like me to provide feel free.
Edit The X509.php file is from phpseclib 1.0.1 phpseclib
I am trying to access WSDL using PHP SOAP. WSDL URL is http://vmwin888.ddns.net:8080/GameLobbyWS/GameLobbyWS.svc?wsdl
It is working fine if we open through browser, but gives error when try to access through PHP SOAP.
I am getting this error...
SOAP-ERROR: Parsing WSDL: Couldn't load from
'http://vmwin888.ddns.net:8080/GameLobbyWS/GameLobbyWS.svc?wsdl' :
Start tag expected, '<' not found
PHP code :
$reqDT = date("Y-m-d H:i:s");
$signature = md5("abcdefg"."GetGameList".$reqDT."123456");
$soap_client = new SoapClient("http://vmwin888.ddns.net:8080/GameLobbyWS/GameLobbyWS.svc?wsdl");
$info = new StdClass();
$info->key = "OperatorID";
$info->value = "abcdefg";
$info->key = "OperatorPassword";
$info->value = "123456";
$info->key = "RequestDateTime";
$info->value = $reqDT;
$info->key = "Signature";
$info->value = $signature;
$param = array($info);
$result = $soap_client->__soapCall('GetGameList',$param);
var_dump($result);
I'm getting an error message when making a call to an xBase++ based web server that is acting as a web service (not using WSDL) when trying to make a soapclient call to it using NuSoap 1.94 with PHP 5.2.17. This exact same code works with NuSOAP 1.94 on PHP 4. Any ideas or help would be appreciated!
Note (I had to remove the https:// part of the addresses from the error message below - I was getting an error posting saying I needed 10 reputation to post 2 links or more)
Thanks,
Salar
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'xxx.xxx.com:55055' : failed to load external entity "xxx.xxx.com:55055" in /hsphere/local/home/xxx/xxx.com/phpinvent/inc/functions/xmsg.php:34 Stack trace: #0 /hsphere/local/home/xxx/xxx.com/phpinvent/inc/functions/xmsg.php(34): SoapClient->SoapClient('https://xxx.xxx...') #1 /hsphere/local/home/xxx/xxx.com/phpinvent/xmsgtest.php(15): XMsg('LOGIN', Array) #2 {main} thrown in /hsphere/local/home/xxx/xxx.com/phpinvent/inc/functions/xmsg.php on line 34
Here's the code of my test page, and the xmsg function:
<?php
ini_set('display_errors', 'On');
ini_set('default_socket_timeout', 300);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// include configuration
require_once('inc/config.php');
require_once('inc/nusoap/nusoap.php'); // include the NuSOAP classes
$xmsg_param[0][0] = "userid";
$xmsg_param[0][1] = "TEST";
$xmsg_param[1][0] = "password";
$xmsg_param[1][1] = "TEST";
$result = XMsg("LOGIN", $xmsg_param);
echo("<br>resulttxt: ".$result['xmsg_resulttxt']);
echo("<br>Sessionid: ".$result['sessionid']);
?>
<?php
// XMsg *************************************************************************
// This function is used to send a message through the robust, connectionless message system
function XMsg($xm_type, $xm_parameters, $xm_target = XMSG_DEFAULT_GATEWAY, $xm_mode = XMSG_DEFAULT_MODE)
{
// Parameters:
// xm_type - C - mandatory – type of message being sent
// xm_parameters - A - optional - 2 dimensional array of name/value pairs that will be sent to the target with the message
// xm_target - C - optional - target - currently supports only URLs of AutoMate agents - defaults to gateway
// xm_mode - C - optional - tokens that allow for modification of the message - currently defaults to #SOAP# to send via SOAP
// Returns:
// xm_result - A - array of name/value pairs returned from the target in same format as xm_target
$xm_SOAPagent = ''; // SOAP Envelope Object - Request
$xm_SOAPresult = ''; // SOAP Envelope Object - Response
$xm_SOAPclass = '';
$xm_retrynum = 0; // Number of retries attempted
$xm_retry = true; // Continue retrying?
$xm_result = Array(); // Array of results returned by XMsg
$xm_numparams = 0; // Number of parameters passed to XMsg
$xm_I = 0; // FOR Loop Counter
// Initialize Parameters
$xm_parameters = (gettype($xm_parameters) == "array" ? $xm_parameters : array());
// check if mandatory parameters are passed
// xm_type must be character and not empty
if (gettype($xm_type)=="string" && !empty($xm_type)) {
switch($xm_mode)
{
case "SOAP":
// open SOAP envelope and initialize
echo("calling xm_target: ".$xm_target."<br>");
$soapclient = new soapclient($xm_target);
$soapparam = array();
// create and pass xmsg structure - NOTE: this section is specialized to PHP
$soapparam['xmsg_id'] = '';
$soapparam['xmsg_source'] = '';
$soapparam['xmsg_target'] = $xm_target;
$soapparam['xmsg_session'] = $_SESSION['SESSIONID'];
$soapparam['xmsg_userid'] = $_SESSION['USERID'];
$soapparam['xmsg_websessid'] = session_id();
$soapparam['xmsg_ip'] = $_SERVER['REMOTE_ADDR'];
$soapparam['xmsg_status'] = 'SENT';
$soapparam['xmsg_type'] = $xm_type;
$soapparam['xmsg_result'] = '';
$soapparam['xmsg_resulttxt'] = '';
$soapparam['xmsg_date'] = date("m/d/y");
$soapparam['xmsg_time'] = date("H:i:s");
$soapparam['xmsg_datereceive'] = '';
$soapparam['xmsg_timereceive'] = '';
$soapparam['xmsg_dateresponse'] = '';
$soapparam['xmsg_timeresponse'] = '';
// count parameters and add to SOAP Envelope
$xm_numparams = count($xm_parameters);
for ($xm_I = 0; $xm_I < $xm_numparams; $xm_I++) {
echo("setting soapparam[".$xm_parameters[$xm_I][0]."] to :".$xm_parameters[$xm_I][1]);
$soapparam[$xm_parameters[$xm_I][0]] = $xm_parameters[$xm_I][1];
}
// SOAP retry loop start - retry until xm_retry is false - set to false when call succeeds or max # retries exceeded
do {
// run remote SOAP call for RemoteCall as specified in
$xm_result = $soapclient->call('XMsg',$soapparam);
// check for fault
echo ("Fault: ".$xm_result['FAULT']."<br>");
echo ("1 Faultcode: ".$xm_result['faultcode']."<br>");
if (empty($xm_result['faultcode'])) {
echo('<hr>'.'<pre>' . htmlspecialchars($soapclient->response, ENT_QUOTES) . '</pre>');
echo('<hr>'.'<pre>' . htmlspecialchars($soapclient->debug_str, ENT_QUOTES) . '</pre>');
$xm_retry = false;
// update status / response date / time
$xm_result['xmsg_status'] = "RECEIVED";
$xm_result['xmsg_dateresponse'] = date("m/d/y");
$xm_result['xmsg_timeresponse'] = date("H:i:s");
} else {
echo("2 faultcode: ".$xm_result['faultcode']);
}
// SOAP Call retry handling
if ($xm_retry) {
// increase the SOAP comm retry counter to count the number of retries made
$xm_retrynum++;
// check if the maximum number of retries has been reached
if ($xm_retrynum <= XMSG_NUMRETRY) {
sleep(XMSG_RETRYDELAY); // delay for set number of seconds
} else {
$xm_retry = false;
}
}
} while ($xm_retry);
break;
default:
// no other message type handling currently
}
}
}
return $xm_result;
// XMsg *************************************************************************
This is quite simple. Your web server can't see the location the WSDL is hosted at. Can you hit the location if you copy the WSDL url and paste it into your browser? You should check that the URL you are using is correct, and whether your web server can even see that location. If not you will need to remedy that before it will work.
I have this code :
$feed = 'urltorss';
$feeds = new SimpleXmlElement( file_get_contents($feed) );
$feed = 'http://www.businessweek.com/feeds/homepage.rss';
$feeds = new SimpleXmlElement( file_get_contents($feed) );
Now both urls don't have any special characters that require url encoding them, but the 2nd url has an .rss extension if it's related.
The first call works and i get a timeout on the 2nd when i try on my server but works perfectly on localhost.
This is the error i'm getting :
Severity: Warning
Message: file_get_contents('http://www.businessweek.com/feeds/homepage.rss')
[function.file-get-contents]:
failed to open stream: Connection timed out
Filename: controllers/mailsystem.php
Line Number: 36
Why is that?
First, check your path so
echo $feed; // just for debug
then check the content
$content = #file_get_contents($feed);
and in the end, get the XML
if( $content ) { $feeds = new SimpleXmlElement( file_get_contents($feed) ); }
Edit: file_get_contents for URLs will only work if you have allow_url_fopen = 1. To get the content of http://www.businessweek.com/feeds/homepage.rss you need a cURL function that gets the content. Something like http://davidwalsh.name/curl-download
I'm trying to get latitude and longtitude from google map by giving address. But it's giving error. When I directly copy url to browser url bar. it's giving correct result. If anybody know the answer.
Here is my code.
<?php
$key = '[AIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0]';
$opt = array (
'address' => urlencode('Kolkata,India, ON') ,
'output' => 'xml'
);
$url = 'http://maps.google.com/maps/geo?q='.$opt['address'].'&output='.$opt['output'].'&oe=utf8&key='.$key;
$dom = new DOMDocument();
$dom->load($url);
$xpath = new DomXPath($dom);
$xpath->registerNamespace('ge', 'http://earth.google.com/kml/2.0');
$statusCode = $xpath->query('//ge:Status/ge:code');
if ($statusCode->item(0)->nodeValue == '200') {
$pointStr = $xpath->query('//ge:coordinates');
$point = explode(",", $pointStr->item(0)->nodeValue);
$lat = $point[1];
$lon = $point[0];
echo '<pre>';
echo 'Lat: '.$lat.', Lon: '.$lon;
echo '</pre>';
}
?>
Following error has occured:
Warning: DOMDocument::load(http://maps.google.com/maps/geo? q=Kolkata%252CIndia%252C%2BON&output=xml&oe=utf8&key=%5BAIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0%5D) [domdocument.load]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C:\xampp\htdocs\draw\draw.php on line 19
Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "http://maps.google.com/maps/geo?q=Kolkata%252CIndia%252C%2BON&output=xml&oe=utf8&key=%5BAIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0%5D" in C:\xampp\htdocs\draw\draw.php on line 19
Notice: Trying to get property of non-object in C:\xampp\htdocs\draw\draw.php on line 26
DOMDocument::load() requires allow_url_fopen to be true.
Check your php.ini-settings and switch it to 1.
See also:
http://php.net/filesystem.configuration.php#ini.allow-url-fopen
What would cause DOMDocument.load to fail loading XML from a URL that is accessible?