我遇到了针对wsdl文件验证我的Web服务的问题。
我在Laravel 5.2框架中使用php,我必须创建一个Soap Web服务器。我已将服务器和客户端类放在Controller(servercontroller.php,clientcontroller.php)和处理在存储库文件夹中传递给服务器的数据的类中。 然后我把我的wsdl文件放在公共文件夹(g1.wsdl)中。 一切顺利,除了当我尝试验证客户端发出的soap请求时,服务器不会对wsdl进行验证。 例如,如果我的wsdl中的元素具有minOccurs =“2”并且我在我的请求中仅传递了一个项目,则脚本继续进行而没有任何类型的验证响应。元素的类型也会出现同样的问题。
这是我的客户:`
<?php
namespace Modules\G1Zucchetti\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use SoapClient;
use SoapFault;
class ClientController extends Controller
{
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
ini_set("soap.wsdl_cache_enabled", "0");
$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
'soap_version' => SOAP_1_2,
'connection_timeout' => 180,
'trace' => 1,
'exceptions' =>true,
)
));
try {
$client = new SoapClient('http://promek.local/soap/base_server/g1.php?wsdl', array('stream_context' => $context));
echo("SOAP Client creato con successo!<br>");
//dd($gsearch->__getFunctions());
$result=$client->RequestActiveLicense( array(
'Piva'=> 'piva',
'CodiceFiscale' =>'cf',
'Identificativo' => 'codiceidentificativo'
));
//dump($client->__getTypes());
//dd($client->__getFunctions());
if($result->ReturnCode == '0000'){
echo("Servizio Disponibile<br>");
$resultUCS = $client->UpdateCompanySetting(
array(
'TokenCode' => $result->TokenCode,
'MastroCliente' => 'mc',
'ContoCliente' => 'cc',
'MerciVenMastro' => 'mvm',
'MerciVenConto' => 'mvc',
'MastroIncassoB' => 'mib',
'ContoIncassoB' => 'cib',
'MastroIncassoC' => 'mic',
'ContoIncassoC' => 'cic',
'DataInvioDati' => '2017-10-04'
)
);
dd($resultUCS);
}else{
echo("Problemi di autenticazione<br>");
dd($result);
}
} catch (SoapFault $exception) {
//dd(trigger_error("SOAP Fault: (faultcode: {$exception->faultcode}, faultstring: {$exception->faultstring})", E_USER_ERROR));
dd($exception->getMessage());
}
}
}
`
这是我的服务器:`
namespace Modules\G1Zucchetti\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use SoapServer;
class ServerController extends Controller
{
/**
* Display a listing of the resource.
* @return Response
*/
public function __construct() {
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 0);
ini_set('default_socket_timeout', 300);
ini_set('max_execution_time', 0);
}
public function index() {
$class = "Modules\G1Zucchetti\Repositories\G1WS";
// options for ssl in php 5.6.5
$opts = array(
'ssl' => array(
'ciphers' => 'RC4-SHA',
'verify_peer' => false,
'verify_peer_name' => false
)
);
// SOAP 1.2 client
$params = array(
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_2,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180,
'stream_context' => stream_context_create($opts)
);
try {
$server = new SoapServer(public_path() . "/soap/base_server/g1.wsdl", $params);
$server->setClass($class);
$server->handle();
exit;
}catch (\SoapFault $e){
dd($e->getTraceAsString());
}
}
}
` 我的自定义课程:
<?php
/**
* Created by PhpStorm.
* User: francesco
* Date: 02/10/17
* Time: 11.54
*/
namespace Modules\G1Zucchetti\Repositories;
use Carbon\Carbon;
use Illuminate\Support\Facades\Session;
use Modules\G1Zucchetti\Entities\G1Users;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
class G1WS {
private $logger;
private $returnCode;
private $tokenCode = null;
private $description;
public function __construct()
{
$this->logger = new Logger('G1WS', array(new StreamHandler(public_path() . '/LOG/G1WS/ws.log', Logger::INFO)));
}
public function RequestActiveLicense($request){
$this->logger->addInfo('RequestActiveLicense', array('input params' => $request));
try{
$g1User = G1Users::where('identificativo', $request->Identificativo)
->where('partita_iva', $request->Piva)
->where('codice_fiscale', $request->CodiceFiscale)
->first();
if(!$g1User){
$this->returnCode = config('g1ws.codici.noLicense.returnCode');
$this->description = config('g1ws.codici.noLicense.description');
}elseif(!G1Users::where('identificativo', $request->Identificativo)
->where('partita_iva', $request->Piva)->first()) {
$this->returnCode = config('g1ws.codici.noMatchPivaIdentificativo.returnCode');
$this->description = config('g1ws.codici.noMatchPivaIdentificativo.description');
}elseif ($g1User->status < 1){
$this->returnCode = config('g1ws.codici.notValidLicense.returnCode');
$this->description = config('g1ws.codici.notValidLicense.description');
}else{
$this->returnCode = config('g1ws.codici.ok.returnCode');
$this->description = config('g1ws.codici.ok.description');
if(!$g1User->token){
$this->tokenCode = $g1User->id_promek_user.(date('Ymdhis'));
$g1User->token = $this->tokenCode;
$g1User->data_scadenza_token = Carbon::now()->addMinutes(30);
$g1User->save();
}else{
$this->tokenCode = $g1User->token;
}
}
}catch (\Exception $e){
$this->logger->addError('RequestActiveLicense', array('exception' => $e->getMessage()));
}
$esito = array('ReturnCode' =>$this->returnCode, 'TokenCode' => $this->tokenCode, 'Description' => $this->description);
$this->logger->addInfo('RequestActiveLicense', array('response' => $esito));
return $esito;
}
public function UpdateCompanySetting($request){
try {
$g1User = G1Users::where('token', $request->TokenCode)
->where('data_scadenza_token','>=',Carbon::now())
->first();
if($g1User){
$this->returnCode = config('g1ws.codici.ok.returnCode');
$this->description = config('g1ws.codici.ok.description');
$this->tokenCode = $request->TokenCode;
//faccio update company setting
$g1User->mastro_cliente = $request->MastroCliente;
$g1User->conto_cliente = $request->ContoCliente;
$g1User->merci_ven_mastro = $request->MerciVenMastro;
$g1User->merci_ven_conto = $request->MerciVenConto;
$g1User->mastro_incasso_b = $request->MastroIncassoB;
$g1User->conto_incasso_b = $request->ContoIncassoB;
$g1User->mastro_incasso_c = $request->MastroIncassoC;
$g1User->conto_incasso_c = $request->ContoIncassoC;
$g1User->data_invio_dati = $request->DataInvioDati;
$g1User->save();
}else{
$this->returnCode = config('g1ws.codici.tokenExpired.returnCode');
$this->description = config('g1ws.codici.tokenExpired.description');
//richiamo l'utente x svuotare il token
$g1User = G1Users::where('token', $request->TokenCode)->first();
$g1User->token = null;
$g1User->data_scadenza_token = null;
$g1User->save();
}
}catch (\Exception $e){
$this->logger->addError('UpdateCompanySetting', array('exception' => $e->getMessage()));
}
$esito = array('ReturnCode' =>$this->returnCode, 'TokenCode' => $this->tokenCode, 'Description' => $this->description);
$this->logger->addInfo('UpdateCompanySetting', array('response' => $esito));
return $esito;
}
}
然后是我的wsdl文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://tempuri.org/"
xmlns:tns="http://tempuri.org/"
name="Webserviceaccesspoint"
>
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="CompanyInfo">
<s:complexType><s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Piva" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="CodiceFiscale" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="Identificativo" type="s:string" />
</s:sequence></s:complexType>
</s:element>
<s:element name="Esito">
<s:complexType><s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="ReturnCode" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="TokenCode" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="Description" type="s:string" />
</s:sequence></s:complexType>
</s:element>
<s:element name="CompanySetting">
<s:complexType><s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="TokenCode" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="MastroCliente" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="ContoCliente" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="MerciVenMastro" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="MerciVenConto" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="MastroIncassoB" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="ContoIncassoB" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="MastroIncassoC" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="ContoIncassoC" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="DataInvioDati" type="s:date" />
</s:sequence></s:complexType>
</s:element>
<s:element name="UpdateCompanySettingResult">
<s:complexType><s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="ReturnCode" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="TokenCode" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="Description" type="s:string" />
</s:sequence></s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="RequestActiveLicenseRequest">
<wsdl:part name="parameters" element="tns:CompanyInfo" />
</wsdl:message>
<wsdl:message name="RequestActiveLicenseResponse">
<wsdl:part name="parameters" element="tns:Esito" />
</wsdl:message>
<wsdl:message name="UpdateCompanySettingRequest">
<wsdl:part name="parameters" element="tns:CompanySetting" />
</wsdl:message>
<wsdl:message name="UpdateCompanySettingResponse">
<wsdl:part name="parameters" element="tns:UpdateCompanySettingResult" />
</wsdl:message>
<wsdl:portType name="RequestActiveLicensePortType">
<wsdl:operation name="RequestActiveLicense">
<wsdl:input message="tns:RequestActiveLicenseRequest" />
<wsdl:output message="tns:RequestActiveLicenseResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="UpdateCompanySettingPortType">
<wsdl:operation name="UpdateCompanySetting">
<wsdl:input message="tns:UpdateCompanySettingRequest" />
<wsdl:output message="tns:UpdateCompanySettingResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="RequestActiveLicenseBinding" type="tns:RequestActiveLicensePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="RequestActiveLicense">
<soap:operation soapAction="http://promek.local/g1zucchetti/server#RequestActiveLicense" style="document" />
<wsdl:input><soap:body use="literal" /></wsdl:input>
<wsdl:output><soap:body use="literal" /></wsdl:output>
<wsdl:documentation>Questo metodo deve essere utilizzato per verificare
se la licenza di utilizzo dell'interfaccia GPE è v
alida o
scaduta/non esistente. E' la prima richiesta avviat
a dal modulo di interfaccia prima di effettuare qua
lsiasi
richiesta successiva. Successivamente viene utiliz
zato il codice Identificativo per identificare l'az
ienda.
Il codice identificativo può essere generato dal pr
ovider del servizio WS in modo univoco come
identificativo di sessione. Nulla vieta di poterlo
utilizzare per un tempo limitato mantenendo lo stes
so.
Successivamente, se scaduto, dovrà esserne richiest
o uno nuovo. </wsdl:documentation>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="UpdateCompanySettingBinding" type="tns:UpdateCompanySettingPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="UpdateCompanySetting">
<soap:operation soapAction="http://promek.local/g1zucchetti/server#UpdateCompanySetting" style="document" />
<wsdl:input><soap:body use="literal" /></wsdl:input>
<wsdl:output><soap:body use="literal" /></wsdl:output>
<wsdl:documentation>Questo metodo deve essere utilizzato per aggiornare
i dati generali dell'azienda in riferimento alle
codifiche, codici piano dei conti, etc. da utilizzare come riferimento. </wsdl:documentation>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Webserviceaccesspoint">
<wsdl:port name="RequestActiveLicensePort" binding="tns:RequestActiveLicenseBinding">
<soap:address location="http://promek.local/g1zucchetti/server" />
</wsdl:port>
<wsdl:port name="UpdateCompanySettingPort" binding="tns:UpdateCompanySettingBinding">
<soap:address location="http://promek.local/g1zucchetti/server" />
</wsdl:port>
</wsdl:service>
是否有任何解决方案可以根据wsdl中设置的选项验证客户端请求?