SOAP-ERROR: Parsing WSDL: Couldn't load - php

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);

Related

php soapserver: Can't import external schema

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.

Attempting to parse XML/JSON from an API output

OK... I am using PHP 5 (be gentle, still learning PHP). CURL is enabled. Attempting to load XML or JSON output from an API to an object and nothing happens. When I manually execute the URL in question, I get what I am expecting.
Here is my code:
class XmlToJson {
public function Parse ($url) {
$fileContents = file_get_contents($url);
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$simpleXml = simplexml_load_string($fileContents);
$json = json_encode($simpleXml);
return $json;
}
}
$_MySQLServer = "localhost";
$_MySQLServerUserName = "";
$_MySQLServerPassword = "";
$_MySQLDatabaseName = "";
$_SSActiveWear_UserID = "*****";
$_SSActiveWear_APIKey = "*****";
$_SSActiveWear_APIBaseURL = "https://*****/v2";
$_CategoryURL = "/categories/";
$_StylesURL = "/styles/";
$_ProductsURL = "/products/";
$_SpecsURL = "/specs/";
$_SSActiveWear_MediaType = "xml";
//$_conn = mysqli_connect($_MySQLServer, $_MySQLServerUserName, $_MySQLServerPassword, $_MySQLDatabaseName);
//Insert or Update Categories
$_URL = $_SSActiveWear_APIBaseURL . $_CategoryURL;
$_URL = $_URL . "?mediatype=$_SSActiveWear_MediaType&UserName=$_SSActiveWear_UserID&Password=$_SSActiveWear_APIKey";
$OBJ = simplexml_load_string($_URL);
print_r($OBJ);
What am I doing wrong?
Edit 1
Added the following code:
$xml = simplexml_load_file($_URL) or die("Error: Cannot create object");
print_r($xml);
and it dies. Does that mean that there is something wrong with the code?
Try this :
$OBJ = simplexml_load_string(file_get_contents($_URL));
If you want to know why your code is not working, you are trying to load XML from URL but "simplexml_load_string" loads XML from string.
I FINALLY figured it out... More to the point I finally found a site on Google that helped. It is the first answer in fsockopen with http authentication problem.
So here is the code that works:
file_get_contents("https://$_SSActiveWear_UserID:$_SSActiveWear_APIKey#$_SSActiveWear_APIBaseURL$_CategoryURL/?mediatype=$_SSActiveWear_MediaType");
mediatype can be either json or xml

Error while loading xml file?

Am dynamically loading an xml file and sending request to the api but getting
Warning: DOMDocument::loadXML(): Empty string supplied as input in /home/spotrech/public_html/ but this error is very inconsistent sometime appear sometime don't! I really no idea how to solve this. below is code
$rechargeApiUrl = "http://allrechargeapi.com/apirecharge.ashx?uid=$uid&apikey=$apike&number=$mobileNo&opcode=$opId&amount=$amount&ukey=$uniId&format=xml";
$url = file_get_contents($rechargeApiUrl);
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML(preg_replace('/(<\?xml[^?]+?)utf-16/i', '$1utf-8', $url));
$itemInfo = $xmlDoc->getElementsByTagName('Result'); //returns an object.
$itemCount = $itemInfo->length;
foreach ($itemInfo as $userInfo) {
//Assigning node values to its specified variables.
$ukey = strtolower($userInfo->getElementsByTagName('ukey')->item(0)->childNodes->item(0)->nodeValue);
$status = $userInfo->getElementsByTagName('status')->item(0)->childNodes->item(0)->nodeValue;
$resultCode = $userInfo->getElementsByTagName('resultcode')->item(0)->childNodes->item(0)->nodeValue;
}
$strStatus = strtolower(trim($status));
$strResultCode = trim($resultCode);
$strCode = trim($ukey);
any response will be appreciated.Thank you

how can call a asmx webservice by parsing an object as parameter,

Here is my code
$objLogParameter = new LogParameters();
$objLogParameter->strLogMessage = $message."&nbsp".$extendedMessage;
$objLogParameter->strStackTrace = $preStackTrace;
$objLogParameter->strUser = "Osmosys";
$objLogParameter->strCustomer = "ws";
$objLogParameter->strPageOrModuleName = "calling ws";
$objLogParameter->strApplication = "OsmTest";
$objLogParameter->strSubscription = "test2";
$objLogParameter->EnumSeverity = "Error";
$objLogParameter->EnumLogType = "ErrorTest";
$url = "http://log.cocoonit.in/writelogsindbservice.asmx?WSDL";
$client = new SoapClient($url, array("trace" => 1));
$res = $client->WriteLogInDB($objLogParameter);
WriteLogInDB is a method in .asmx webservice, thats method except an object as a argument then if i pass a object in $res i got a msg like status code = 0,object couldn't be empty.
I want to connect this Url
http://log.cocoonit.in/writelogsindbservice.asmx
and in this it have a WriteLogInDB method, i want to call this method by passing an object nothing but $objLogParameter. how can i do it in php.
Please help me.

Getting error in Amazon product API sample code (PHP)

I downloaded Product Advertising PHP Soap Library and was going through the sample codes. I configured the value of 'AWS_API_KEY', 'AWS_API_SECRET_KEY', 'AWS_ASSOCIATE_TAG', 'AWS_ANOTHER_ASSOCIATE_TAG' in sampleSettings.php file. I'm getting the below mentioned error in my browser while trying to access 'sampleItemSearch.php'.
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl' : Start tag expected, '<' not found
I tried to take help help from Link: https://forums.aws.amazon.com/thread.jspa?messageID=270273 but it did not work.
Note: I have tried to run the below url in browser and got the following output:
$request="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AssociateTag=ASSOCIATETAG01-20&AWSAccessKeyId=MY_ACCESS_KEY_ID&Operation=ItemSearch&Version=2011-08-01&SearchIndex=Books&Keywords=harry%20potter&Timestamp=2013-04-10T12%3A44%3A42.000Z&Signature=ASasd5645AdSG878asdHsaHJ9YTefl1F6i0%3D";
Please suggest what I should do.
I solved it at last. Below mentioned code is working fine.
AWSAccessKeyId = "*******************";
$SecretAccessKey = "******************************";
$AssociateTag = "***************";
$ItemId = '****'; //10 or 13 digit isbn
$Timestamp = gmdate("Y-m-d\TH:i:s\Z");
$Timestamp = str_replace(":", "%3A", $Timestamp);
$ResponseGroup = "ItemAttributes,Images";
$ResponseGroup = str_replace(",", "%2C", $ResponseGroup);
$String = "AWSAccessKeyId=$AWSAccessKeyId&AssociateTag=$AssociateTag&IdType=ISBN&ItemId=$ItemId&Operation=ItemLookup&ResponseGroup=$ResponseGroup&SearchIndex=Books&Service=AWSECommerceService&Timestamp=$Timestamp&Version=2011-08-01";
$String = str_replace("\n", "", $String);
$Prepend = "GET\nwebservices.amazon.com\n/onca/xml\n";
$PrependString = $Prepend . $String;
$Signature = base64_encode(hash_hmac("sha256", $PrependString, $SecretAccessKey, True));
$Signature = str_replace("+", "%2B", $Signature);
$Signature = str_replace("=", "%3D", $Signature);
$BaseUrl = "http://webservices.amazon.com/onca/xml?";
$SignedRequest = $BaseUrl . $String . "&Signature=" . $Signature;
$XML = simplexml_load_file($SignedRequest);
print_r($xml); // output

Categories