login button

Can't call method Java web service from PHP client (in WSDL mode)

Forums :

Hellow!

I created PHP client for Java web service. I use WSDL mode.

During a call of a method I receive an error: "Namespace Error".

In Apache2 error-log:

[Mon Dec 24 12:11:16 2007] [error] [client 127.0.0.1] PHP Notice: Trying to get property of non-object in D:\\server\\wso2\\scripts\\dynamic_invocation\\wsf_wsdl_client_request.php on line 164, referer: http://127.0.0.1:8080/exchange/

[Mon Dec 24 12:11:16 2007] [error] [client 127.0.0.1] PHP Notice: Undefined variable: ele_ns in D:\\server\\wso2\\scripts\\dynamic_invocation\\wsf_wsdl_client_request.php on line 166, referer: http://127.0.0.1:8080/exchange/

wsf_wsdl_client_request.php  have error!? :)

Thanks

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Can't call method in wsdl mode

Hi darlikin,

Can you attach your wsdl ,so that we can reproduce the problem.

-- Nandika

I have the same problem

I'm using WSO2 WSF/PHP 1.2 using the Fedora core 6 wso2-wsf-php-1.2.0-1.i386.rpm.

My code is the following:

<?php

try {   
    $policy = new WSPolicy(array("security" => array("useUsernameToken" => TRUE)));
   
    $securityToken = new WSSecurityToken(array(
        "user" => "OMITTED",
                "password" => "SECRET));

    $client = new WSClient(array(
        "wsdl"=>"http://novellaqalive.mhhe.com/rmsws/UserServices?wsdl",
        "policy" => $policy,
        "securityToken" => $securityToken));

    $proxy = $client->getProxy();

    $result = $proxy->login(array("userName" => "OMITTED", "password" => "SECRET"));

    echo "The service replied: '";
    var_dump($result);
    echo "'\n";
}
catch (Exception $e) {
        if ($e instanceof WSFault) {
            $fault = $e;
                printf("Soap Fault received with code '%s' and reason '%s'\n",
                        $fault->code, $fault->reason);
        } else {
                printf("Exception caught with message '%s'\n", $e->getMessage());
        }
}
 
?>

I also get the Namespace error (with or without correct credentials).

As you can see from the code, you can get the WSDL here:

http://novellaqalive.mhhe.com/rmsws/UserServices?wsdl

 

Thanks in advance,

Asger Ottar Alstrup
Area9

 

how to connect to java webservice from php

Hi ,

  I am a newbie to php i have created java webservice with simple method and deployed it in tomcat created WSDL for it. and have to call the java webservice from php. when i am connecting it php client is connecting to java webservice but it is unable to pass any arguments to the called method giving java.lang.NullPointerException. if u have a sample application to connect both can u plz give it. thanks in advance.

Java service with php client

Hi, here I have attached simple service (only add operation is implmented) with Axis2/Java service and WSF/PHP client.

AttachmentSize
client.php_.txt343 bytes
services.xml1.84 KB
java_source.zip33.1 KB
CalculatorDoc.wsdl6.81 KB

Cant i call a webservice (java) deployed in apcahe tomcat

Thanks for sending me the program. I didn't test it till now coz i dont have axis soft with me. i just want to know that can't i invoke java webservice deployed in apache tomcat. or is it neccesary to use AXIS. I am getting an error when i am calling a web service deployed in apache tomcat using php. i.e.. it is not sending data to the web method from php.thanks

WSDL-mode

Hi,

The answer to the first question is you should be able to call  a web service in different platform from WSF/PHP. But there can be problems in WSF/PHP with some WSDLs. Can you send us the WSDL, so we can figure out the problem,

 

Thanks,

Dimuthu

PHP in WSDL mode

Hi,

I have attached the WSDL file . so in this it has not specified the input members (data types and names) of each methods like add ,sendName etc, although the java webservice has methods with variables (web service is created in netbeans 6.0) & deployed in tomcat 6 version. so when i am calling this webservice from php it is calling the methods but it is not passing any value to the methods there.

i am getting following output in java console for Webservice method when called :

 :: Thread[http-8084-2,5,main]
Data is ::: null

 

thanks

AttachmentSize
webservice.txt1.19 KB
CalculatorWS.wsdl2.65 KB

Missing XSD referred from your wsdl,

Hi Adilz.cool,

I checked your WSDL and it refers to the scheman in the follwoing location

http://localhost:8084/CalculatorWSApplication/CalculatorWS?xsd=1

 which I cannot access.

Although I can generate it from your service class, since rightnow I don't have installed tomcat, It would be quicker if you can send the .xsd file as well..

 

Thanks

Dimuthu

 

 

XSD is here

Hi this is my xsd attached and some code in php i am using to call the JWS is here :

<?php
// include the SOAP classes
require_once('nusoap.php');
// define parameter array (ISBN number)
$param = array('name'=>"Asak");
// define path to server application
$serverpath ='http://localhost:8084/CalculatorWSApplication/CalculatorWS?wsdl';
//define method namespace
$namespace="xs:int";
// create client object
$client = new soapclient($serverpath);
echo("Connected");
// make the call
    $price = $client->sendName("sendName",$param,$namespace);
echo("Connected here ");

?>

thanks

AttachmentSize
calculatorxsd.xsd1.49 KB

PHP code with Web service Framework for PHP

Hi I was able to use the service  with Web Service Framework for PHP, but with little changes to the WSDL. That is the xml comment in the WSDL had  to be removed. I attached the wsdl with the change.

 

Here is the PHP code,

<?php

$client = new WSClient(array("wsdl" => "CalculatorWS.xml"));

$proxy = $client->getProxy();

$ret = $proxy->sendName(array("name" => "test"));

echo $ret["return"];

?>

 

Thanks

Dimuthu

AttachmentSize
CalculatorWS.xml2.41 KB

PHP is Connect to JWS with out Error

Thanks for reply,

 I was trying it since yesterday & i got it without any changes in my WSDL file. here is sample code for that.

require_once('nusoap.php');
  /* create the client for my rpc/encoded web service */
 $wsdl = "http://localhost:8084/webserviceproj/WebServicesService?wsdl";
  $client = new soapclient($wsdl,array('trace' => 1));

/* Initialize parameter */
$params = array('i'=>"ASD");

// Method name
 $response = $client->__soapCall('simple', array('parameters' => $params));
     print_r($response->return);
Now i am trying to connect to DB and return a set of values (array) and capture it in PHP to display it in the client side. from client side i am passing a name "i" whose data i am querying to DB to fetch data. so is there a need to query DB to get data in XML format using XMLELEMENT command in oracle or what  should be done to send back an array of data from JWS

I am using a String Array to store data n send it back to PHP . in .net we have Dataset to fill up data n send it back . sample code is here for (JWS).

public String[] simple(@WebParam(name = "i")
    String i) {       
        String res[] = new String[3];

/// Connection code goes here     
        if(rs.next()){
          res[0] = rs.getString(1) ;
                   res[1]=rs.getString(2) ;
                           res[2]= rs.getString(3);   }

Out put is here :

Array ( [0] => 5 [1] => Adil [2] => hyd )

Response: <?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Body><ns2:simpleResponse xmlns:ns2="http://sample/">

<return>5</return><return>Adil</return>

<return>hyd</return></ns2:simpleResponse></S:Body></S:Envelope>

thanks

java service with php client

i ma new to web service

can u please help me understand the concept to call a java web service form php client . how to run the simple service you have given . help me

First in the samples it

First in the samples it demonstrates how to call php service from php client. If you are able to install wsf/php correctly you should be able to run the samples without much problem.

Then if you have a java service you may be able to get the wsdl from the service. WSDL describes the service interface and request, response message format. From the wsf/php you can generate php client code using wsdl2php.php (shiped with wsf/php pack). This will generate a set of classes and some methods that actually invokes the service. What you need to do is construct your input message with the parameters passed to generated classes and write the logic for handling response. Please go through the manual for more information on wsf/php clients
http://wso2.org/project/wsf/php/1.3.2/docs/index.html

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.