尝试使用 PHP 使用 Java Web 服务时出现以下错误:java.lang.NullPointerException
.
我认为归结为正确传递参数。但是,此链接在我的情况下不起作用(提供 stdClass 对象)。
这是 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>
相关PHP代码:
//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);
的格式化转储$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) ""
}
}
}
}
}
更新#1
WSDL 评论:Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-
。
更新#2
在 WSDL 中未找到元素标记,但存在模式位置。加载时发现以下元素标签
<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>
更新#3
解决方案:
$addRequest = new stdClass();
$queryByPartyIdInMsg = new StdClass();
$queryByPartyIdInMsg->partyId="12345";
$addRequest->queryByPartyIdInMsg = $queryByPartyIdInMsg;
$theResponse = $soapClient->queryByPartyId($addRequest);
var_dump($theResponse);
找到元素结构后,前面提到的链接实际上有助于找到解决方案。