PHP 调用Java WebService

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Cc_Rain0624/article/details/84098697

Java开发的Webservice 接口参数熟String类型的 第三方为php调用。

-<xsd:element name="EmmResut">
-<xsd:complexType>
-<xsd:sequence>
	<xsd:element name="string" type="xsd:string" nillable="true" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

以上是java webservice的部分内容。参数是传入string类型 其实是json的字符串。
PHP中正常调用都是使用:

$client = new SoapClient($WSDL_URL);
1、$client->FunctionName($param1,$param2);
2、$client->__soapCall("FunctionName",array($param1,$param2));
3、$client->__soapCall("FunctionName",array("param1"=>$param1,"param2"=>$param2));

但是这样调用 总是返回 空指针异常。
SoapClient正常使用方法

解决方法:

header("Content-type: text/html; charset=utf-8");  
$webservice_url = "XXXXXXXXXX/service/IWoCheck?wsdl";
$client = new SoapClient($webservice_url);

$time_ago = microtime(true);
$param = array('PK_POINTCHECK' =>'1001A110000000B39UV1','PK_POINTCHECK_B' => '1001A110000000B39UV2', 'PK_PCUSER' => 'Y14050801','PK_PCRESULT'=>'001A4100000000LUQBI','PCMEAS_RESULT'=>'webservice');
$json['string']=json_encode($param);
print_r($json);
try{
    $arr = $client->__soapCall('EmmResut', array($json));
}catch(Exception $e){
    $arr = $e->getMessage();    
}
$time_end = microtime(true);
echo 'webservice执行时间差为:'.($time_end-$time_ago).'s<br>';
print_r($arr);

指定下参数名称 因为wsdl中:

<xsd:element name="string" type="xsd:string" nillable="true" minOccurs="0"/>

解决灵感来源于:
PHP调用Java Webservice

猜你喜欢

转载自blog.csdn.net/Cc_Rain0624/article/details/84098697