Thursday, January 28, 2010

Accessing Webservices from PHP

Normally, most of the current windows products provides webservice for many of its functionalities. Particularly the sharepoint 2007 server, has lot of webservice that external applications can use it.

Again, accessing those webservices through .NET is pretty easy with its built in function. But, to access it through languages like PHP, requires some analysis, particularly for those who are doing it for first time.
The nusoap.php is a populat choice to access the webservice via Php.

It can be downloaded from the following sourceforge URL.

href="http://sourceforge.net/project/showfiles.php?group_id=57663

Here is the code snippet to access it

require_once( '/nusoap.php');

$client = new soapclient('http://ctsgvcchannel1/_vti_bin/SearchWebService.asmx',false,$proxyhost, $proxyport, $proxyusername, $proxypassword);

$client->setcredentials($username,$password);

$err = $client->getError();

if ($err) {

echo '

Constructor error

' . $err . '
';

}

// Doc/lit parameters get wrapped

$param = array('strKeyWord' => 'java','pageLength'=>(int)'5');

$result = $client->call('SimpleSearch', $param, '', 'http://tempuri.org/SimpleSearch', false, true);

// Check for a fault

if ($client->fault) {

echo '

Fault

';

print_r($result);

echo '
';


} else {

// Check for errors

$err = $client->getError();

if ($err) {

// Display the error

echo '

Error

' . $err . '
';


} else {

// Display the result

echo '

Result

';

print_r($result);

echo '
';


}

}

echo '

Request

' . htmlspecialchars($client->request, ENT_QUOTES) . '
';


echo '

Response

' . htmlspecialchars($client->response, ENT_QUOTES) . '
';

Saturday, January 23, 2010

Web Services - How does it work and where to use ?

Web Service has been the new buzz word in the past few years. In this post we will explore the basic elements of it and where it can be applied.

Consider this scenario a JAVA application running in a server and has an access to a stock price data base, where the recent stock prices are updated and you have a stand alone .NET stand alone application running in your computer from which you want to access the stock prices and display it in your computer. Remember you cannot be provided access to their database. So what is the solution ???

You face 2 problems

  • You dont have access to their database
  • The application that has access to the database is totally a different platform
How do you overcome such a situation? .. The answer is webservice.
If the a JAVA method that could fetch the data is exposed to the outside world that listens to the incoming requests and sends back the requested data that would be perfect isn't it?..

WebService uses HTTP protocol to send the request and response in SOAP (Simple Object Access Protocol) format.

There should be a contract to access the webservice this is provided by WSDL -Web Services Definition Language, it is also a XML file containing the method names and their return types and lot more. To learn more about webservice visit this page.

Friday, January 15, 2010

Know the core libraries in Java

Java differs from other languages in that the number of classes and interfaces in its standard libraries is very large.Beginners to Java should take note that very many common tasks have already been implemented in the libraries. The most widely used packages are probably java.lang, java.util, java.sql, and java.io.

As well, the libraries

* are built by experts
* generally improve their performance over time
* are widely used, and form defacto standards

Implementing something which already exists in the libraries is probably wasted effort.Significant changes and additions to the standard libraries occur in each major release, and it pays to keep current. For example, the 1.4 release of the JDK includes regular expressions, assertions, logging services, and more, in its list of new features. The Java 5 release has several major new features, including generics, an enhanced for loop, enums, autoboxing, and metdata. The Java 6 release has no new language features, and is not as dramatic as the 1.5, but it still has some interesting new features, such as scripting, the JConsole monitoring tool, and various Swing improvements.

Sunday, January 10, 2010

You can compare String objects in a variety of ways, and the results are often different. The correctness of your result depends largely on what type of comparison you need. Common comparison techniques include the following:

  • Compare with the == operator.
  • Compare with a String object’s equals method.
  • Compare with a String object’s compareTo method.
  • Compare with a Collator object.
  • Comparing with the == Operator
The == operator works on String object references. If two String variables point to the same object in memory, the comparison returns a true result. Otherwise, the comparison returns false, regardless whether the text has the same character values. The == operator does not compare actual char data. Without this clarification, you might be surprised that the following code snippet prints The strings are unequal.

String name1 = “Michèle”;
String name2 = new String(”Michèle”);
if (name1 == name2) {
System.out.println(”The strings are equal.”);
} else {
System.out.println(”The strings are unequal.”);
}

The Java platform creates an internal pool for string literals and constants. String literals and constants that have the exact same char values and length will exist exactly once in the pool. Comparisons of String literals and constants with the same char values will always be equal.

Comparing with the equals Method
The equals method compares the actual char content of two strings. This method returns true when two String objects hold char data with the same values. This code sample prints The strings are equal.

String name1 = “Michèle”;
String name2 = new String(”Michèle”);
if (name1.equals(name2) {
System.out.println(”The strings are equal.”);
} else {
System.out.println(”The strings are unequal.”);
}

Comparing with the compareTo Method
The compareTo method compares char values similarly to the equals method. Additionally, the method returns a negative integer if its own String object precedes the argument string. It returns zero if the strings are equal. It returns a positive integer if the object follows the argument string. The compareTo, method says that cat precedes hat. The most important information to understand about this comparison is that the method compares the char values literally. It determines that the value of ‘c’ in cat has a numeric value less than the ‘h’ in hat.
String w1 = “cat”;
String w2 = “hat”;
int comparison = w1.compareTo(w2);

Tuesday, January 5, 2010

How to get time information in java.sql.Date?

The answser is you cannot.
java.sql.Date does not store/retrieve any information related to time.

So, how do you solve the problem of saving the date with time in your database?

Simple… use java.sql.Timestamp. There are methods in java.sql.PreparedStatement and java.sql.Statement to set the timestamp.

Sunday, January 3, 2010

PIC Microcontroller Programming Tutorials - Part 1

See the basics of using MikroC compiler and Oshonsoft PIC simulator.



Proceed to the next part >>