Java 从php调用SOAP web服务时接收web方法参数的空值

Java 从php调用SOAP web服务时接收web方法参数的空值,java,php,web-services,webservice-client,Java,Php,Web Services,Webservice Client,我有一个用Java编写的Soap Web服务 我从php调用这个web服务,并将参数传递给web方法,但在web方法处得到null 我的Web服务如下所示: @SOAPBinding(style = Style.RPC) @WebService(serviceName = "Test") public class Test { @WebMethod(operationName = "hello") public String hello(@WebParam(na

我有一个用Java编写的Soap Web服务

我从php调用这个web服务,并将参数传递给web方法,但在web方法处得到null

我的Web服务如下所示:

@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;
    }
}
<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>
$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);
Request : Hello null , null
WSDL的消息部分如下所示:

@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;
    }
}
<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>
$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);
Request : Hello null , null
此调用的输出如下所示:

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)
服务器日志中的输出如下:

@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;
    }
}
<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>
$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);
Request : Hello null , null
我尝试了不同的解决方案,但没有任何效果,仍然无法将参数发送到web方法,在web方法处始终为null。

尝试以下方法:

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

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

在撞了我的头两天后找到了解决办法。问题是,使用web服务的PHP脚本正在使用缓存的soap WSDL。在我的PHP脚本的开头添加以下行之后,问题就解决了

解决方案:[在PHP代码的开头添加这一行]

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

在撞了我的头两天后找到了解决办法。问题是,使用web服务的PHP脚本正在使用缓存的soap WSDL。在我的PHP脚本的开头添加以下行之后,问题就解决了

解决方案:[在PHP代码的开头添加这一行]

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

请阅读-总结是,这不是一个理想的方式来解决志愿者,可能会适得其反获得答案。请不要将此添加到您的问题中。请阅读-总结是,这不是解决志愿者问题的理想方式,可能会对获得答案产生反作用。请不要将此添加到您的问题中。在敲打我的头两天后找到了解决方案。您的解决方案和我的解决方案都是相同且正确的,问题是使用web服务的PHP脚本使用了缓存的soap WSDL。在我的PHP脚本开头添加以下行后,问题得到了解决。解决方案:“ini_set(“soap.wsdl_cache_enabled”,“0”)”[在PHP代码的开头添加这一行]我建议您改为编辑PHP.ini,我真的很困惑,当您说它不起作用时,无论如何,我很高兴您发现解决方案编辑PHP.ini并不总是起作用,不建议这样做,尤其是在live server上部署时,因为您可能无法始终更改php.ini,但可以将“soap.wsdl\u cache\u enabled=0”放在.htaccess中。不管怎样,再次感谢。在撞了我的头两天后找到了解决办法。您的解决方案和我的解决方案都是相同且正确的,问题是使用web服务的PHP脚本使用了缓存的soap WSDL。在我的PHP脚本开头添加以下行后,问题得到了解决。解决方案:“ini_set(“soap.wsdl_cache_enabled”,“0”)”[在PHP代码的开头添加这一行]我建议您改为编辑PHP.ini,我真的很困惑,当您说它不起作用时,无论如何,我很高兴您发现解决方案编辑PHP.ini并不总是起作用,不建议这样做,尤其是在live server上部署时,因为您可能无法始终更改php.ini,但可以将“soap.wsdl\u cache\u enabled=0”放在.htaccess中。无论如何,再次谢谢你。