Saturday, August 13, 2011

SOAP - simple Object Access Protocol

SOAP , NuSOAP and WSDL - Web Service Description Language(Web Service Definition Language):


What is SOAP?

SOAP is a standardized means of transferring data between two machines in a client-server configuration. SOAP is a W3C standardized (W3C, 2004) means of communicating with a web service across a network (local or Internet).

“SOAP is an XML-based messaging protocol.” (SoapUser.com, 2009)

SOAP messages (envelopes) are formed in XML, itself an open W3C standard. The client must haves an XML parser to interpret the document. XML is platform and programming language independent so it can be used by a wide range of computer systems. As SOAP is just a standard and not a process, it is not limited to any particular protocol (although HTTP is commonplace).

“WSDL is a document written in XML. The document describes a Web service. It specifies the location of the service and the operations (or methods) the service exposes.”(w3schools, 2009)

WSDL (Web Service Description Language) defines the web service and available methods to the client. This applies to all clients no matter from what context they are consuming the application.

The WSDL document also defines the following:

* The methods arguments
* The arguments data types
* Return value data type
* Port and binding data.

Example structure of a WSDL document: (w3schools, 2009)


<definitions>

<types>
definition of types........
</types>

<message>
definition of a message....
</message>

<portType>
definition of a port.......
</portType>

<binding>
definition of a binding....
</binding>

</definitions>

WSDL documents are very important to web services (and SOAP) because it is effectively a protocol that defines in very clear detail how the client will interact with it. A WSDL document also eliminates guess work and long laborious documentation. WSDL language is not easily readable by humans (despite being written in XML), especially when they get long. There are now several implementations of SOAP that ease the process and enable rapid application development. One example of this is NuSOAP.
What is NuSOAP?

“…the most viable PHP implementation of SOAP seems to be Dietrich Ayala’s SOAPx4, also known as NuSOAP” (Apple Inc, 09)

NuSOAP is a collection of classes that allows for rapid development of SOAP enabled PHP web services. NuSOAP is not a technology in itself, in the sense that it does not require any reconfiguration on the server, but rather acts as a middle man to ease the application development process.

Hello, World! Example [Server] (Nichol, 2004)


<?php

// Pull in the NuSOAP code

require_once('nusoap.php');

// Create the server instance

$server = new soap_server;

// Register the method to expose

$server->register('hello');

// Define the method as a PHP function

function hello($name) {

return 'Hello, ' . $name;

}

// Use the request to (try to) invoke the service

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

$server->service($HTTP_RAW_POST_DATA);

?>

The above example demonstrates a NuSOAP server with one method that returns the same value that was passed to it (as a string).

Walkthrough:

* Reference the NuSOAP implementation
* Create a new instance of the server object, and name it.
* Register the method “hello” with the server object.
* Write the corresponding method and make it do “something”. (In this case, return the same string that was originally passed to it).
* If [when] there is post data, pass it to the server object and do something with it.

The code above is as basic as a NuSOAP example gets, but it shows clearly the steps required to start making use of SOAP without having to write (or even fully understand) the implementation yourself.

Hello, World! Example [Client] (Nichol, 2004)


<?php

// Pull in the NuSOAP code

require_once('nusoap.php');

// Create the client instance

$client = new soapclient('http://localhost/phphack/helloworld.php');

// Call the SOAP method

$result = $client->call('hello', array('name' => 'Scott'));

// Display the result

print_r($result);

?>

The client code is similar by design. Even though this example uses only PHP, it is possible to access the server using virtually any other language.

Walkthrough:

* Reference the NuSOAP implementation
* Create an instance of the SOAPClient and specify the remote path of the web service.
* Call the desired method and pass an argument (called ‘name’).
* The web service responds (if request is valid) and prints the result to the screen.

The disadvantage of using third party implementations is that debugging and error handling is more difficult, as you have no knowledge of the underlying code.

Create CSS Stylesheet and JavaScript for Print

Create CSS Stylesheet and JavaScript for Print


When we want to print out HTML page we need a lighter version of our HTML page. Basically, we don’t want to print the background images, background colors, advertisements and other things which are not relevant in printing. For this purpose, we need to specify a CSS stylesheet which browser use when we print our HTML page. We can also change the width and layout of our HTML page. We can specify our CSS stylesheet for print like this.

Print.php:

<html>
<head>
<title>CSS stylesheet for Print</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/print.css" type="text/css" media="print" />
</head>
<body>
<div class="coupon-mini">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="146" align="left" valign="top"><div class='default-coupon'><img src='/sites/default/files/coupon_116_116.'></div></td>
<td width="354" align="left" valign="top">
<h3 style="font-family: 'palatino linotype',palatino; line-height:18px; padding:6px 0 0 0; color:#0e549c; ">
Divan Restaurant and Hookah Lounge, Alabama
</h3>
<div class='coupons-text1'><span>McDonald 20% Off.</span><p>McDonald 20% Off.</p></div><br />
<div style="clear:both;"></div>
<div class="detail-basic1">
3125 Piedmont Rd NE, Atlanta, Alabama<br>
<strong> Phone Number :</strong> (404) 365-0410<br/>
<strong> Pincode:</strong> 30305 <div class="openhr1"><strong> Opening Hours:</strong> 6:30 PM to 01:00 AM</div>
<div class="web1">
<div class="lft1"><a href="#" class="about-web-link">http://www.divanatlanta.com</a></div>
<div class="rght1"><a href="#" class="about-mail-link">ajay0878@yahoo.com</a></div>
</div>
</div>
</td>
</tr>
</table>
</div>
<div class="print noprint"><a href="javascript:window.print();" class="coupon-print-link">Print this Coupon</a></div>
</body>
</html>


Print.css:

.noprint
{
display:none;
}

Style.css:

.header
{
width:800px;
height:200px;
}

IF U NEED CUSTOM PAGE BREAK

Advanced CSS Printing — Using CSS Page Breaks

I have one customer that absolutely insists his web pages print perfectly. Why? Because he refuses to look at his pages on the screen -- he tells his employees to print the website for him to look at. And since he looks at pages that way, he believes most of his customers do just this.

Needless to say, I've learned quite a few tricks to making a website print properly. I've already shared methods for making your website content printer-friendly, as well as making your website structure printer-friendly. One important aspect of making your pages printer-friendly is by using CSS/XHTML page breaks.

There are numerous spots that are good for page breaks:

* Between page sections (h2 or h3 tags, depending on your site format)
* Between the end of an article and subsequent comments / trackbacks
* Between longs blocks of content

Luckily, using page breaks in CSS is quite easy.
The CSS

The all and print medias should be addressed:
PRINT.CSS:

@media all
{
.page-break { display:none; }
}

@media print
{
.page-break { display:block; page-break-before:always; }
}



The first declaration ensures that the page-break is never seen visually...while the second ensures that the page break is seen by the printer.
The HTML

Creating a simple DIV element with the page-break class is how you implement the page break.

<div class="page-break"></div>

Quite simple, huh?
The Usage

<h1>Page Title</h1>
<!-- content block -->
<!-- content block -->
<div class="page-break"></div>
<!-- content block -->
<!-- content block -->
<div class="page-break"></div>
<!-- content block -->
<!-- content -->

There you have it. The importance of page breaks in the web should not be understated, as many users still print content regularly. Also note that your content may be printed into PDF format and shared.