FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Access Java 1.6 Web service using php client





sheetal_nikam
We have written web service in Java 1.6 using JAX-WS. We need to call the methods from this web service using PHP Nusoap library.

In Java 1.6; we use Endpoint.publish method to publish the web service. Hence we dont require any container(so we are using Java1.6 which internally supports HTTP server) .

The PHP client code can parse the WSDL generated by Java code but when a method is called PHP client receives Null Pointer exception (fault).

Please help me in solving this problem.

Java Code:

package example;
import javax.jws.WebService;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
import java.util.*;

@WebService
public class Calculator {

public void add() {
int a=10;
//System.out.println("Add Method call");
//return a+b;
}

public static void main(String[] args){
// create and publish an endpoint
Calculator calculator = new Calculator();
Endpoint endpoint = Endpoint.publish("http://localhost:9999/calculator", calculator);
}
}


PHP code:

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Pull in the NuSOAP code
require_once('lib/nusoap.php');

$client = new soapclient('http://localhost:9999/calculator?wsdl', true);

// Check for an error
$err = $client->getError();

if ($err) {
// Display the error

echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
// At this point, you know the call that follows will fail
}

// Call the SOAP method

$result = $client->call('add');

if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
badai
i don't use nusoap (since php itself can handle soap)


Code:
// DON'T CACHE the SOAP on the PHP server
$ini = ini_set("soap.wsdl_cache_enabled","0");
$client = new SoapClient("http://localhost:9999/calculator?wsdl", array("user_agent"=>"some_string"));
//your parameter to send
$p = array("whatever" => $whatever);
//the soap function might require nested type
$p1 = array("whatever2" => $p);

try{
 $ret = $client->yourfunction($your_paramater_like_p_or_p1);
 print json_encode($ret);
 //or var_dump($ret);
}
catch (SoapFault $exception)
{
    print 'SOAP Error ';
    print json_encode($exception);
    //or var_dump($exception);
}


you can get function and type from your soap service using
Code:
print "<pre>";
var_dump($client->__getFunctions());
var_dump($client->__getTypes());


and don't bother with your WDSL if it's generated by Java. usually what happen is you send the wrong parameter in your function.
Related topics
[tutor] How to protect images without htaccess using PHP
Using PHP
Includ Images using PHP.
How to start using PHP? Help!
A very good PHP MySQL Tutorial
Web Designer
Website Designing using PHP
how can i setup a page break for printer on html using php ?
Access Internet On Your Phone Using Pc Internet., Free No Gp
Reading word documents using PHP?
I am trying to build a contact form using php and flash
how to compress a file using php ?
Using php to change content of a .txt
Can I add tasks to Windows Scheduled Tasks - Using PHP?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.