简体   繁体   中英

receiving null value of parameters of web method when calling SOAP Web Service from php

I have a Soap Web service written in Java.

I'm calling this web service from php and passing parameters to the web method but getting null at the web method.

My Web Service as follows:

@SOAPBinding(style = Style.RPC)
@WebService(serviceName = "Test")
public class Test {

        @WebMethod(operationName = "hello")
        public String hello(@WebParam(name = "name1") String txt1, @WebParam(name = "name2") String txt2) {

            System.out.println("Request : Hello " + txt1+" , "+txt2);
            return "Response : Hello " + txt1 + " ! " + txt2;
    }
}

And the message part of the WSDL is as follows:

<message name="hello">
<part name="name1" type="xsd:string"/>
<part name="name2" type="xsd:string"/>
</message>
<message name="helloResponse">
<part name="return" type="xsd:string"/>
</message>

And Calling webservice from php as follows:

$client = new SoapClient("http://localhost:8081/androidWebServiceTest/Test?wsdl"); // soap webservice call

$functions = $client->__getFunctions();    // getting list of web methods

$types = $client->__getTypes();    // getting types

$response = $client->hello(array("parameters" => array("name1" => "test1", "name2" => "test2")));    // calling web method hello

// dumping $functions, $types and $response
var_dump($functions);    
var_dump($types);
var_dump($response);

Output of this call is as follows :

D:\wamp64\www\WebService\netbeans\Monitor2Test\test.php:49:
array (size=1)
  0 => string 'helloResponse hello(hello $parameters)' (length=38)
D:\wamp64\www\WebService\netbeans\Monitor2Test\test.php:51:
array (size=2)
  0 => string 'struct hello {
 string name;
}' (length=30)
  1 => string 'struct helloResponse {
 string return;
}' (length=40)
D:\wamp64\www\WebService\netbeans\Monitor2Test\test.php:53:
object(stdClass)[3]
  public 'return' => string 'Response : Hello null ! null' (length=19)

And the output in the server log is as follows:

Request : Hello null , null

I tried different solution, but nothing worked for me, still can not able to send parameters to web method, always getting null at the web method.

try this:

<?php
// ...    
$soapClient->hello([
    'name1' => 'test1', 
    'name2' => 'test2'
]);
// or 
$soapClient->__soapCall('hello', [
    'parameters' => [
        'name1' => 'test1', 
        'name2' => 'test2'
    ]
]);

Found solution After banging my head for 2 days. The problem was that my PHP script which is consuming the web service is using cached soap WSDL. The problem is solved after adding this following line in the beginning of my PHP script.

Solution: [add this line in the starting of the PHP code]

ini_set("soap.wsdl_cache_enabled", "0");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM