php SoapServer not print any xml document - php

all
I create a soap server use below code. I found it is a little hard to create wsdl document in PHP .so I decide use non-wsdl mode.
$soapServer = new SoapServer(NULL,array('uri'=>'http://com.test.env',
'encoding'=>'UTF-8'));
$soapServer->addFunction("workprocess_orders_api_add");
$soapServer->addFunction("workprocess_list_api_get_local_name");
$soapServer->handle();
but when I try to access this program, it print nothing. both web-browser and program(I use SoapClient)
$client = new SoapClient(NULL,array('uri'=>'http://com.test.env',
'location'=>'http://localhost/~breeze.kay/ams/workprocess/api/soap/',
'trace'=>1,
'style' => SOAP_DOCUMENT,
'use' => SOAP_LITERAL));
var_dump($client->__call('workprocess_orders_api_add',array())); //print null
var_dump($client->__getFunctions()); //print null
I tired call some function like this at client-side:
echo $client->sayHello('test');
I get error:
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in /Users/breeze.kay/Sites/ad-test/soap.php:15
where is wrong ? I have no idea.:( the code looks ok. why there is no print?

OK, I tried it out.
the problem is the request url must append ?wsdl ,like this: http://localhost/wbs/api.php?wsdl
but I use url-rewrite for my sites. the rewrite rule break the original url struct.
by the way, dose somebody know where talk about the url rule for soap request?
I read some manual not find it.

The XML document not found error usually occurs when there is an empty space before php opening or after closing tag, try clearing that and test.

Related

CakePhp Getting Entity 'raquo' not defined error when calling SOAP wdsl file

Im trying to connect to the FedEx PHP plugin, Ive successfully ran the plugin with my local Server. But when I try to run it on my CakePhp project I get the next error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://my-subdomain.mydomain.com/controller/wsdl' : Entity 'raquo' not defined
Using the url I can actually enter the wdsl page and see the file in XML file. I got a function and view which return this. This is that functions code:
public function wsdl() {
$this->layout = false;
$this->RequestHandler->respondAs('xml');
}
I can enter the url and see the correct display of the XML. Then when I try using the wsdl on my function which is in the same class I get the error above. This is the code I use to call the SOAP class:
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "http://apibebe2go.bebe2go.com/home/wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
I get and internal error from the CakePhp debug and the error above. Any ideas what I could try to make this work? If you guys need any more code Ill be happy to help :D
Ok I solved the problem another way. Not sure why the /wdsl file was not working when called via function to view, BUT I added the .wdsl file to the WebRoot file path I had and called the url from there. Now it works like it should. If you need further explanation on how I achieved this, feel free to ask here :D
Cheers! :P

Problem in updating an XML file using PHP DOMDocument();

I am trying to write a function that updates the Site Map of a website or technically adds an entry to sitemap.xml file. The standard structure of a Google sitemap can be seen here: http://www.sitemappro.com/google-sitemap.html
Following is the code of that function:
function AddEntry($loc,$lastmod,$changefreq,$priority){
$xmlDoc = new DOMDocument();
$xmlDoc->load("sitemap.xml");
$url []=array('loc' => $loc, 'lastmod' => $lastmod, 'changefreq'=> $changefreq, 'priority' =>$priority );
$r=$xmlDoc->createElement("url");
$xmlDoc->appendChild($r);
foreach($url as $key=>$value)
{
$r->appendChild($xmlDoc->createElement($key))->appendChild($xmlDoc->createTextNode($value));
}
$xmlDoc->save();
}
The above code is not working and giving this error:
"Fatal error: Uncaught exception 'DOMException' with message 'Invalid Character Error' in..."
Can you please help by correcting my code? Thanks in advance.
As pointed out in a comment the issue should be in this line
$r->appendChild($xmlDoc->createElement($key))->appendChild($xmlDoc->createTextNode($value));
Most likely you're adding some url characters to your XML. The problem is that you must escape them or surround your $value with a CDATA section. Otherwise the generated XML will be invalid and the xml library will throw that kind of exceptions.
P.S. I don't remember if the htmlentities function is good also for xml, I suppose that, but you'll need to investigate about that.

Magento API call for getting products information

I used the below code to get products details from a magento store from my localhost
$proxy = new SoapClient('http://domain.com/magento/index.php/api/soap/?wsdl');
$sessionId = $proxy->login('username', 'apikey');
$filters = array(
'sku' => array('like'=>'test%')
);
$products = $proxy->call($sessionId, 'product.list', array($filters));
var_dump($products);
It works on my localhost machine but not on server. But soap configuration is enabled in server. Below is the error message
" SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in "
I got corresponding xml file when I used the below URL
http://domainname/shoponline/index.php/api/soap/?wsdl
I removed index.php but didn't get any result.
$proxy = new SoapClient('http://domain.com/magento/index.php/api/soap/?wsdl');
The above statement display the below error
Parsing WSDL: Couldn't find definitions in
Looks like the WSDL XML file was not loaded at all. To debug, try to open this file in your browser.
I guess it will not be loaded at all and you'll get an error (which will help you to find out what's wrong) or you will be asked to input username and password (basic HTTP auth). In the second case try change your URL from http://domain.com/magento/index.php/api/soap/?wsdl to http://user:pass#domain.com/magento/index.php/api/soap/?wsdl
Make sure you disable developer mode and error reporting in index.php.
Open the "hosts" file from C:\windows\system32\drivers\etc and comment out the line ::1 (like this: # ::1) or remove the line altogether, then save the file.
I've also used this service - http://localhost:81/magento/index.php/api/soap/?wsdl and it works for me.
The SoapClient unable to retrive wsdl definition file which means that routing is not configured correctly or there some external error occurs. But most likely it's a routing problem. The api/[type] rewrite rule is commented in .htaccess, so you need to remove # sign or use api.php directly. To make api.php work directly you need to pass type parameter to api.php to specify which API protocol you would like to use.
For example, for SOAP it will be - http://domain.com/magento/api.php?type=soap&wsdl. You can also use 'soap_v2'.

PHP: DOMDocument loadHTML returns error with nesty URL in href

Recently I get an exception while I try to implement a special template engine.
Mine problem with DOMDocument load is in fact that I use some place holders in href and it will be replaced after with real values. I want to store that template and to use it each time when I need it, here is code sample
$this->dom = new DOMDocument;
$load_html = $this->dom->loadHTML($html);
And nesty part of HTML looks like
Visit our web site
and exception is
Fatal error: DOMDocument::loadXML() [<a href='domdocument.loadxml'>domdocument.loadxml</a>]: EntityRef: expecting ';' in Entity
I was try to find a some way to skip that check but couldn't find anything.
This causes no error in PHP 5.3. You must have some other HTML that is causing this. Normally you see this when you use an entity with no ; after it.
Foo &nbsp Bar
That throws that same error for me. Look for some entity without a ; on it. Browsers will render that, but it is not correct.
I found what was the problem. In my URL it was & sign, I was replace it with & and now it works.

exception not being caught

I have the following PHP code on a web page:
$wsdl_url = "someURL?wsdl";
try {
$client = new SoapClient($wsdl_url, array('login' => 'mylogin','password' => 'mypassword'));
$client->myWebMethod(); // <-- problem call
} catch (Exception $e) {
echo "none";
}
It's a basic call to a web service. The problem is that when an error is thrown on the line $client->myWebMethod(), echo "none" is not printed. In fact, nothing in the catch block runs. Hence, I don't think the exception is being caught.
A fatal error is displayed on the web page.
Question: Any ideas on why this is happening? I expected all exceptions to be caught and handled with this code. But what I'm getting is that the fatal error is being displayed on the page. Maybe web services are handled differently?
EDIT: the error is that it's missing a bunch of required parameters. if I add the parameters the call works fine. I am purposely omitting the parameters to get the error, so i would know how to handle it.
The error is something like: Fatal error: SOAP-ERROR: Object hasn't 'myparameter1'
Thanks in advance.
I got the same exact problem this morning while running a custom module for Drupal which required an external SOAP Web Service. To be honest, I'm not quite sure how I solved the problem.
Turns out it was all about clearing my Web Server's cache that had to do with the respective WSDL. In your tmp/ folder you will find various files named wsdl-yourservice-etc. Delete them and it should be OK. If not, the problem lies in the code and more specifically in the sequence and syntax of the arguments passed to the WSDL.
I hope I helped.
Unfortunately, this is not a catchable error.
However, you can check if the soap extension is loaded before trying to instantiate it by calling get_loaded_extensions with something along the lines of:
if (in_array('soap', get_loaded_extensions())) {
// it's loaded!
}

Categories