Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Tuesday, May 25, 2010

Web Service development using NuSOAP on XAMPP and client in .net using C#

Recently, one of my customers wanted to expose their Web Services for the service users. They wanted to keep the data centralized in their website and allow it to be accessed by Desktop Client software on user’s consoles. As the Website is built using Wordpress as a CMS, all the data is managed well by Wordpress. So we started exploring a PHP based solution to create the web service compliant to Web Services Description Language (WSDL) 1.1. We finally zeroed on NuSOAP.

Getting started with NuSOAP was not at all a difficult job (Thanks to Scott Nichol’s tutorial). Once you get a feel of it, just follow his Programming with NuSOAP Using WSDL tutorial and you are done!

For the Web Service development, I preferred running the NuSOAP on my http://localhost using XAMPP. I already had the wordpress with test data readily installed there in. As I was developing the Desktop Client App using .net, I felt it comfortable to have both NuSOAP and client to be on my machine, for development phase.

Getting NuSOAP working on XAMPP was as easy as in following steps:

  1. Download the latest version of NuSOAP (Version 0.9.5, while writing this post)
  2. Download the documents (Optional)
  3. Extract nusoap-0.9.5.zip and copy the lib directory into a folder in XAMPP environment. I created a folder webserv under my C:\xampp\htdocs\ folder and copied the lib directory there.
  4. Create a web service script. e.g. server.php in webserv folder. And in the server.php include the nusoap.php file. (Refer to the code snapshot below)

/*********** server.php ***************************************/

/* including MySql Database wrapper functions and config file */
require("Database.class.php");
require("config.inc.php");

/* including new soap functions */
require_once("lib/nusoap.php");

$ns="MyWebService";

$server = new soap_server();
$server->configureWSDL('B2BManager',$ns);
/* B2BManager is the name of web service */
$server->wsdl->schemaTargetNamespace=$ns;

…

…

Now you will be able to use NuSOAP calls in your web service, such as $server->register & $server->wsdl->addComplexType, as required.

After the Web Service setup, next thing was to request these services from the Desktop Application. This can be done by adding web service as a “Web Reference” in the .net solution. Following steps are involved in creating “Web Reference” in .net solution:

Add the Web Service URL, Discover and Add Reference. In the current example, the URL is : http://localhost/webserv/server.php?wsdl. Once this URL is entered, it will discover the services available. In this example, it discovered 1 service, i.e. B2BManager.

add-web-reference

 

add-web-reference-wsdl

Note: In case there’s any problem with the server.php, the generated WDSL may not be well formed. This results in failure in discovering the services. Try navigating to the URL on any browser to see, if the WSDL is proper. If the WSDL is proper, you should see a well formed XML stream as an output. (For e.g. try navigating to Amazon Web service; URL: http://webservices.amazon.com/AWSECommerceService/US/AWSECommerceService.wsdl.

Call the web service in your code. Declare the web service variable in the class that you want it to be called as below:

B2BManager.localhost.B2BManager webService_ = null;

webService_ = new B2BManager.localhost.B2BManager();

webService_.GetProducts();

Friday, April 16, 2010

SMF 1.1.11 Upgrade Error: The Upgrader found some old or Outdated Language Files

Its always fun to work with free/open source software :) SMF forum software is one such thing. Every time I feel a sense of achievement; especially after my website is well indexed and experiencing a surge of visitors.

Well, after the fix as explained in my previous post, I got few calls from my forum members saying “I can’t see my Personal Messages”, “I can’t view my own profile” and so on…

I started doubting the fix and planned to do a “large upgrade”, as its no harm and any database table discrepancies would also get fixed. It was as simple as following the steps:

But while copying the new files to your forum directory, you need to be very careful and make sure all the new source files are copied properly… or else the following error is certain and the update will fail:

Upgrade Error: The Upgrader found some old or Outdated Language Files

But, in my case, the problem was little different. I had used few mods & templates that used utf-8 language dependencies. Hence, even after copying the files properly, I got the above said error. Forum Maintenance tools were very helpful here. I could easily trace that the language files *.english-utf8.php (in folder smf_1-1-11_upgrade\Themes\default\languages of the downloaded SMF upgrade package) were mismatched in version. I started looking for latest version of utf-8 version of english language, but I couldn’t find them. (Actually I had got them bundled with the theme).

I was pretty sure, I had not used any support for other languages except plain ‘english’. So, I simply made copies of language files that were part of new SMF package and renamed the file names from *.english.php to *.english-utf8.php. This fix got me going with upgrade process…

That’s not all! While upgrading, it threw a cool warning …

Updating and creating indexes...
    Updating indexes on "messages"... done.
    Updating table indexes... done.
    Reordering boards and categories... done.
    Updating indexes and data on "smileys"... Unsuccessful!

This query:

ALTER TABLE smf_smileys
ORDER BY LENGTH(code) DESC;
Caused the error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LENGTH(code) DESC' at line 2

This one was easy to resolve, seems like classic problem! This post was extremely helpful. Simply follow those steps if at all you get this above said “Smiley” issue.

Finally my forum is up .. but my member complaints are not yet addressed. I guessed the complaints were related to some issue with the “Permissions” in SMF forum. Yes, it was ! Somewhere in the process of error checking the database and repairing the tables, the “permissions” had somehow got ignored. Once I set all the “Permission” as I wanted them to be, the forum is UP and Running normal (I think).

Thursday, April 15, 2010

SMF – Database Error and Forum Maintenance

Well, even if you keep your SMF forum updated regularly, you can’t avoid few weird things (Remember Murphy's Law?). I had a stint with such an error with SMF forum. When I navigate to my forum, it threw a Database Error. Not much information was available on that screen. I logged into the database to trace any errors (logged in smf_log_errors) using phpMyAdmin.

As I wrote in previous post, I did a repair of all the tables of SMF database, using phpMyAdmin. This fixed the problem as much to allow me to log into the forum and reach the Admin area.

SMF has given few tools for forum maintenance, as listed below:

Optimize all tables to improve performance.
Check all files against current versions.
Find and repair any errors.
Recount all forum totals and statistics.
Empty out unimportant logs.
Convert HTML-entities to UTF-8 characters

Before touching any of these, I prefer taking a backup. SMF Admin area provides a tool for that too in “Forum Maintenance - Backup Database” section. Please do take a backup; it helps in case the forum maintenance tools go insane.

After the backup, command “Find and repair any errors”. Hmm… here the story starts..It diagnosed an error and possible fix. Here it is …

Note: It appears that your database may require an upgrade. Your forum files are currently at version SMF 1.1.11, whereas your database is at version SMF 1.1.5. It is recommended that you execute the latest version of upgrade.php.

This happens as a result of improper upgrade of the forum software. On every patch release, the SMF update functionality provided in the SMF admin area can be executed to keep it up-to-date. This update script sometimes skips updating the mySQL database tables. Version to version, there could be some changes to the database tables. If such database updates are skipped or failed internally (Update doesn’t display these warnings/failures), it will leave the database in the old version and all other sources will get updated to latest release! Strange thing is, after the update, your forum is running smoothly … until a day, when you see “Database Error”. (Note: I don’t know the reason for Why it worked smoothly first?)

After digging through lot of posts/forums on net, I found a solution appreciated by many here. But, I was not lucky with that. It reported that “the sources and language files are not the latest ones”. Upon my continued search on net, I got a clue on how to fool this script not to throw the above said warning and somehow get on to forum maintenance. Well, its as simple as running the following SQL query.

UPDATE `smf_settings` SET `value`='1.1.11' WHERE `variable`='smfVersion' LIMIT 1;

Now, you should be able to do “Find and repair any errors”. This will do some helpful stuff.  Then, do “Empty out unimportant logs”; this will cleanup the extraneous logs that add unnecessary weight on you database. And do a “Recount all forum totals & statistics”.

It should bring life back to your SMF forum.

Note: These are the steps followed by me as an immediate fix, to at least bring up my forum. So, I don’t know the actual cause of the error. Time & usage will tell us whether it has really worked. At the same time, I am scout for a good, clean & elegant forum software. I will keep you updated.

Wednesday, April 14, 2010

SMF Error: smf error 2: Unable to save result set

I have been using SMF forum software for almost 2 years now. This is one of those freely available forum software, and I found it as the one that is easy for customization and is easy to use. The ‘Ease’ factor drastically falls, if you look at the source code, though. But, I always prefer open source for in case of crash/ or no-support, I can get my hands dirty and straighten it.

Today my SMF forum crashed throwing,

smf error 2: mysql_query() [<a href='function.mysql-query'>function.mysql-query</a>]: Unable to save result set

I looked into the database using, phpMyAdmin tool that my web hosting provider has given. I started checking through the “smf_log_errors” table to find out the cause. It had several errors, including simple logs such as “login password is not matching” and stuff like that .. and I also found the above quoted “Unable to save result set”. Then, I analyzed the table “smf_log_errors” using phpMyadmin. I found the following errors:

smf_log_errors    analyze    Error    Table './my_smf_log_errors' is marked as crashed and should be repaired

smf_log_errors    analyze    Error    Table 'smf_log_errors' is marked as crashed and should be repaired

smf_log_errors    analyze    error    Corrupt

I though, it would all be fine if I “repair” only this table. But it didn’t work that way. I had to finally repair all the tables.

In case you find similar issue, please do a ‘repair’ of all tables in the respective database.

Following are the steps (listed for quick use):

  1. Open the respective database using myPhpAdmin tool. You need the username and password for the database. In case you have forgotten, check out the “/forum/Settings.php” file for username and password. You will find them assigned to “$db_user” and “$db_passwd”.
  2. Do Select All of all tables.
  3. Repair by selecting “Repair table” action. You can also check the errors by selecting “Analyze table”.

Now, you SMF forum should be back to working.

As I analysed the whole problem, it looks like, the cause for this kind of errors is the over grown “smf_log_errors” table size. So, I recommend deleting the read error logs, once in a while.