SOAP Web服务函数仅获得第一个值


SOAP Webservice function getting first value only

我必须创建一个web服务,但我没有这方面的经验,所以我使用SOAP和在web上找到的一些代码。webservice应该在一个函数上获得三个值,两个是字符串,一个是JSON,其中包含我将解码插入mySQL的数据。

但我有以下错误,我的函数只得到第一个值,JSON可以作为一个简单的字符串吗?最后,为什么utf8()会给我错误?我之所以尝试这样做,是因为这是一个西班牙语数据,我们有可能破坏json解码的重音符号。打印值时,所有函数变量都会得到我传递的第一个变量。

这是SERVER的PHP代码:

<?php
if(!extension_loaded("soap")){
      dl("php_soap.dll");
}
require_once '../modulos/conexion.php';//connects to DB
function net_stat() {
    $msj = "Web Service en linea";
    return($msj);
}
function net_receive($token, $tabla, $json_encode) {
    $val_token = '8mp8';
    $stat = 'TOKEN: ' .$token.'<br>tabla: '.$tabla.'<br>Json: <br>'. $json_encode;
    //$json_datos = utf8($json_encode);<--Commented because throws unknown error
    //$json_query = json_decode($json_datos, true);
    $json_query = json_decode($json_encode, true);
    if ($val_token == $token) {
        switch ($tabla) {
            case 'cab_usuarios':
                cab_usuarios($json_query);
                $receiver_msg = 'Query realizado a $tabla';
                break;
            default:
                $receiver_msg = $tabla . ' no es un nombre de tabla valido';
                break;
        }
    } else {
        $receiver_msg = 'Token de autenticacion no valido';
    }
    cerrar_conexion_sql();
    $receiver_msg = $stat . '<br>' .$receiver_msg;
    return $receiver_msg;
}
function cab_usuarios($json_query) {
    foreach ($json_query as $row) {
        $id_usua = $row["id_usua"];
        $co_usua = $row["co_usua"];
        $no_usua = $row["no_usua"];
        $ds_pass = password_hash($row["ds_pass"], PASSWORD_BCRYPT);
        $st_usua = $row["st_usua"];
        $fe_ingre = $row["fe_ingre"];
        $co_user = $row["co_user"];
        $eTInf = $row["eTInf"];
        $aTSuc = $row["aTSuc"];
        $aTInf = $row["aTInf"];
        $co_vende = $row["co_vende"];
        $query = "INSERT INTO dbfar_cabusuarios (`id_usua`, `co_usua`, `no_usua`, `ds_pass`, `st_usua`, `fe_ingre`, `co_user`, `eTlnf`, `aTSuc`, `aTlnf`, `co_vende`) VALUES ($id_usua, $co_usua, $no_usua, $ds_pass, $st_usua, $fe_ingre, $co_user, $eTInf, $aTSuc, $aTInf, $co_vende)";
        mysql_query($query);
    }
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer('farletza.wsdl');
$server->addFunction("net_stat");
$server->addFunction("net_receive");
$server->handle();

这是客户端的PHP代码

<?php
// turn off the WSDL cache
ini_set("soap.wsdl_cache_enabled", "0");
$cliente = new SoapClient("http://localhost:8080/farletza/svc/farletza.wsdl");
$estadowebsvc = $cliente->net_stat();
echo "<strong>".$estadowebsvc."</strong><br/>";
$token = "8mp";
$tabla = "cab_usuarios";
//$json = "json";
$json = '[{"id_usua": "1","co_usua": "003", "no_usua": "jonathan", "ds_pass": "1234", "st_usua": "A", "fe_ingre":"12-04-2015", "co_user": "FARM", "eTInf": "0", "aTSuc": "2", "aTInf": "52EX", "co_vende": "Hernán"}]';
$conexion_remota = $cliente->net_receive($token, $tabla, $json);
echo $conexion_remota;

这是WSDL}

<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='Farletza' 
  targetNamespace='http://localhost:8080/farletza/svc/farletza.wdsl' 
  xmlns:tns='http://localhost:8080/farletza/svc/farletza.wdsl' 
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
  xmlns='http://schemas.xmlsoap.org/wsdl/'> 
<message name='net_statRequest'> 
  <part name='symbol' type='xsd:string'/> 
</message> 
<message name='net_statResponse'> 
  <part name='Result' type='xsd:string'/> 
</message> 
<message name='net_receiveRequest'> 
  <part name='symbol' type='xsd:string'/>
  <part name='symbol' type='xsd:string'/>
  <part name='symbol' type='xsd:string'/>
</message> 
<message name='net_receiveResponse'> 
  <part name='Result' type='xsd:string'/> 
</message> 
<portType name='FarletzaPortType'> 
  <operation name='net_stat'>
    <input message='tns:net_statRequest'/> 
    <output message='tns:net_statResponse'/>   
  </operation>
  <operation name='net_receive'>
    <input message='tns:net_receiveRequest'/> 
    <output message='tns:net_receiveResponse'/>   
  </operation>    
</portType> 
<binding name='FarletzaBinding' type='tns:FarletzaPortType'> 
  <soap:binding style='rpc' 
    transport='http://schemas.xmlsoap.org/soap/http'/> 
  <operation name='net_stat'> 
    <soap:operation soapAction='urn:localhost:8080-farletza#net_stat'/> 
    <input> 
      <soap:body use='encoded' namespace='urn:localhost:8080-farletza' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </input> 
    <output> 
      <soap:body use='encoded' namespace='urn:localhost:8080-farletza' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </output> 
  </operation>
  <operation name='net_receive'> 
    <soap:operation soapAction='urn:localhost:8080-farletza#net_receive'/> 
    <input> 
      <soap:body use='encoded' namespace='urn:localhost:8080-farletza' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </input> 
    <output> 
      <soap:body use='encoded' namespace='urn:localhost:8080-farletza' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
    </output> 
  </operation>       
</binding> 
<service name='FarletzaService'> 
  <port name='FarletzaPort' binding='FarletzaBinding'> 
    <soap:address location='http://localhost:8080/farletza/svc/farletza_server.php'/> 
  </port> 
</service>
</definitions>

这是我从客户那里得到的回报:

Web Service en linea
TOKEN: 8mp
tabla: 8mp
Json: 
8mp
Token de autenticacion no valido

可以看出,所有变量都得到相同的值,为什么会发生这种情况?

如果有人来到这里想知道我的错误,那就是在WSDL上,我对输入消息的部分使用了相同的名称,所以这里有

<message name='net_receiveRequest'> 
  <part name='symbol' type='xsd:string'/>
  <part name='symbol' type='xsd:string'/>
  <part name='symbol' type='xsd:string'/>
</message> 

应该是

<message name='net_receiveRequest'> 
  <part name='symbol1' type='xsd:string'/>
  <part name='symbol2' type='xsd:string'/>
  <part name='symbol3' type='xsd:string'/>
</message>

所以它得到了3个独立的值。一个非常简单的错误。