I'm getting the following error when attempting to consume a Java web service using PHP: java.lang.NullPointerException
.
I think it boils down to passing the parameter correctly . However, this link didn't work in my case (providing an stdClass object).
Here is the relevant part of the WSDL
...
<message name="queryByPartyId">
<part name="parameters" element="tns:queryByPartyId"/>
</message>
...
<operation name="queryByPartyId">
<soap:operation soapAction=""/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
<fault name="ServiceFault"><soap:fault name="ServiceFault" use="literal"/></fault>
</operation>
Relevant PHP code:
//things I've tried
//$theResponse = $soapClient->queryByPartyId("12345");
//$theResponse = $soapClient->__soapCall("queryByPartyId", array("queryByPartyId"=>12345));
//$theResponse = $soapClient->__soapCall("queryByPartyId", array("12345"));
//$addRequest = new stdClass();
//$addRequest->queryByPartyId = 12345;
//$theResponse = $soapClient->queryByPartyId($addRequest);
$theResponse = $soapClient->queryByPartyId(array("queryByPartyId"=>12345));
var_dump($theResponse);
The formatted dump of $theResponse
:
object(SoapFault)#9 (10) {
["message":protected]=> string(30) "java.lang.NullPointerException"
["string":"Exception":private]=> string(0) ""
["code":protected]=> int(0)
["file":protected]=> string(51) "/path/to/index.php"
["line":protected]=> int(82)
["trace":"Exception":private]=> array(2) {
[0]=> array(6) {
["file"]=> string(51) "/path/to/index.php"
["line"]=> int(82)
["function"]=> string(6) "__call"
["class"]=> string(10) "SoapClient"
["type"]=> string(2) "->"
["args"]=> array(2) {
[0]=> string(14) "queryByPartyId"
[1]=> array(1) {
[0]=> array(1) {
["queryByPartyId"]=> int(12345)
}
}
}
}
[1]=> array(6) {
["file"]=> string(51) "/path/to/index.php"
["line"]=> int(82)
["function"]=> string(14) "queryByPartyId"
["class"]=> string(10) "SoapClient"
["type"]=> string(2) "->"
["args"]=> array(1) {
[0]=> array(1) {
["queryByPartyId"]=> int(12345)
}
}
}
}
["previous":"Exception":private]=> NULL
["faultstring"]=> string(30) "java.lang.NullPointerException"
["faultcode"]=> string(8) "S:Server"
["detail"]=> object(stdClass)#6 (1) {
["exception"]=> object(stdClass)#7 (1) {
["stackTrace"]=> object(stdClass)#8 (1) {
["frame"]=> array(40) {
[0]=> string(0) ""
[1]=> string(0) ""
[2]=> string(0) ""
[3]=> string(0) ""
[4]=> string(0) ""
[5]=> string(0) ""
[6]=> string(0) ""
[7]=> string(0) ""
[8]=> string(0) ""
[9]=> string(0) ""
[10]=> string(0) ""
[11]=> string(0) ""
[12]=> string(0) ""
[13]=> string(0) ""
[14]=> string(0) ""
[15]=> string(0) ""
[16]=> string(0) ""
[17]=> string(0) ""
[18]=> string(0) ""
[19]=> string(0) ""
[20]=> string(0) ""
[21]=> string(0) ""
[22]=> string(0) ""
[23]=> string(0) ""
[24]=> string(0) ""
[25]=> string(0) ""
[26]=> string(0) ""
[27]=> string(0) ""
[28]=> string(0) ""
[29]=> string(0) ""
[30]=> string(0) ""
[31]=> string(0) ""
[33]=> string(0) ""
[35]=> string(0) ""
[36]=> string(0) ""
[37]=> string(0) ""
[38]=> string(0) ""
[39]=> string(0) ""
}
}
}
}
}
Update #1
WSDL comment: Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-
.
Update #2
No element tags were found in the WSDL, however a schema location was present. When loaded, the following element tag was found
<xs:complexType name="queryByPartyId">
<xs:sequence>
<xs:element name="queryByPartyIdInMsg" type="tns:queryByPartyIdInMessage" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="queryByPartyIdInMessage">
<xs:sequence>
<xs:element name="partyId" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
Update #3
Solution:
$addRequest = new stdClass();
$queryByPartyIdInMsg = new StdClass();
$queryByPartyIdInMsg->partyId="12345";
$addRequest->queryByPartyIdInMsg = $queryByPartyIdInMsg;
$theResponse = $soapClient->queryByPartyId($addRequest);
var_dump($theResponse);
Once you find the element structure, the link mentioned previously actually helped to find the solution .
Take a second look at the wsdl file, somewhere in there, you'll see something like this:
<element name="queryByPartyId">
<complexType>
<element name="foobar" type="foo:int"/>
</complexType>
</element>
This is the description of what the service expects you to pass when calling it. the inner elements
have name
and type
attributes. To translate that into a call, just do this:
$response = $soapClient->queryByPartyId(array('foobar'=> 123456));
var_dump($response);
The wsdl should also contain a description of what the service will return:
<element name="queryByPartyIdResponse">
<complexType>
<element name="PartyReturn" type="xs:SomeType" />
</complexType>
</element>
In this example, the response will be an object (or whatever your soapclient returns) with 1 property: PartyReturn
, that property will be of the type SomeType
. If it's a custom type (a Java class) the wsdl file will contain a description of that, too.
In your case:
$response = $soapClient->queryByPartyId(
array('queryByPartyIdInMsg' => array('PartyId' => 123456))
);
Or perhaps you'll need to wrap the queryByPartyIdInMsg
sub arrays into another array, because both complexTypes have a minOccurs of 0 (suggesting an array)
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.