将复杂的soap xml请求转换为php数组,将其作为参数传递给nusoap_client

时间:2018-05-16 04:59:05

标签: java php xml soap-client nusoap

我正在编写一个php脚本来调用用java编写的soap webservice。之前我曾经使用带有xml请求的soap UI调用服务并且它曾经工作过。但是当我尝试从php调用服务时它会抛出错误,因为它无法将请求转换为正确的java对象.xml请求是:

<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v3="http:///services/common/commondf/v3/" xmlns:inp="http://..confidential.../input/">
   <soapenv:Header>
      <v3:Info>
         <requestId>Sample</requestId>
      </v3:Info>
   </soapenv:Header>
   <soapenv:Body>
      <m:Input xmlns:m="http://../conf/ident/ial/../input/">
         <a>
            <b>
               <scheme>123</scheme>
               <value>aaa</value>
            </b>
            <c>
               <date>2018-04-09</date>
               <e>
                  <scheme>1234</scheme>
                  <value>bbb</value>
               </e>
            </c>
            <f>
               <scheme>seniority type</scheme>
               <value>ccccccct</value>
            </f>
            <g>....
...........................
.........................
      </m:Input>
   </soapenv:Body>
</soapenv:Envelope>

xml太大而且复杂,所以我不能继续按对象转换它的xml数组。我使用的是simple_xml_load_string,如下所示:

$xml= file_get_contents('test.xml');
$xml_array =  simplexml_load_string($xml);
$array = json_decode(json_encode($xml), true);
try {           
$wsdl='http://localhost/service?wsdl';      
require_once('nusoap.php');
$endpoint = "http://localhost/service";

$mynamespace = "http://something/input/";
$client = new nusoap_client($endpoint);
$err = $client->getError();
if ($err) 
{
   echo  $err;
}
$response = $client->call('Input', $array , $mynamespace);
print_r($response);
}catch(Exception $e){
    var_dump($e->getMessage());
}

当我点击这个时我得到的错误是

  

数组([faultcode] =&gt; soap:客户端[faultstring] =&gt;创建问题   SAAJ对象模型)

在我的soap应用程序中,调用函数定义如下:

java method:
    public output inputDetails(Input input) throws someException 
    {
            ----logic-----
    }

所以基本上我觉得'input'对象没有在方法中正确传递,这意味着php array $ array中的一些问题。如何将soap ui中使用的复杂xml转换为php数组,以便正确转换为java对象.. 还是另外一个问题?谁能请帮忙。

0 个答案:

没有答案