2016-04-12 8 views
3

Ich habe ein seltsames Problem versucht, einen SOAP-Service mit PHP zu konsumieren. Es ignoriert meine Anfrage und gibt das Ergebnis des letzten Befehls zurück! Der SOAP befindet sich in einer Registrierkasse, die ein 'fehlerhaftes' WSDL auf einen öffentlichen IP-Endpunkt hat und ich musste es manuell bearbeiten. Die WSDL-Datei ist in http://192.168.1.20/MyEcrResponce.wsdl das ich es heruntergeladen und ersetzt alle falschen IP-Referenzen mit ‚192.168.1.20‘ und dann gespeichert ich es lokal als MyEcrResponce.wsdl:PHP SOAP hält alte Ergebnisse zurück

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://192.168.1.20/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://192.168.1.20/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 
    <wsdl:types> 
    <s:schema elementFormDefault="qualified" targetNamespace="http://192.168.1.20/"> 
     <s:element name="Cmd"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="1" maxOccurs="1" name="CmdText" type="s:string" /> 
      </s:sequence> 
     </s:complexType> 
     </s:element> 
     <s:element name="CmdResponse"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="1" maxOccurs="1" name="CmdReply" type="s:string" /> 
      <s:element minOccurs="1" maxOccurs="1" name="LcdLine1" type="s:string" /> 
      <s:element minOccurs="1" maxOccurs="1" name="LcdLine2" type="s:string" /> 
      </s:sequence> 
     </s:complexType> 
     </s:element> 
     <s:element name="GetAppStatus"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="1" maxOccurs="1" name="SerialNo" type="s:string" /> 
      <s:element minOccurs="1" maxOccurs="1" name="RetData"  type="s:string" /> 
      </s:sequence> 
     </s:complexType> 
     </s:element> 
     <s:element name="GetAppStatusResponse"> 
     <s:complexType> 
      <s:sequence> 
      <s:element minOccurs="1" maxOccurs="1" name="GetAppStatusResult" type="s:unsignedByte" /> 
      <s:element minOccurs="1" maxOccurs="1" name="RetData" type="s:string" /> 
      </s:sequence> 
     </s:complexType> 
     </s:element>  
    </s:schema> 
    </wsdl:types> 
    <wsdl:message name="CmdSoapIn"> 
    <wsdl:part name="parameters" element="tns:Cmd" /> 
    </wsdl:message> 
    <wsdl:message name="CmdSoapOut"> 
    <wsdl:part name="parameters" element="tns:CmdResponse" /> 
    </wsdl:message> 
    <wsdl:message name="GetAppStatusSoapIn"> 
    <wsdl:part name="parameters" element="tns:GetAppStatus" /> 
    </wsdl:message> 
    <wsdl:message name="GetAppStatusSoapOut"> 
    <wsdl:part name="parameters" element="tns:GetAppStatusResponse" /> 
    </wsdl:message> 
    <wsdl:portType name="MyEcrResponceSoap"> 
    <wsdl:operation name="Cmd"> 
     <wsdl:input message="tns:CmdSoapIn" /> 
     <wsdl:output message="tns:CmdSoapOut" /> 
    </wsdl:operation> 
    <wsdl:operation name="GetAppStatus"> 
     <wsdl:input message="tns:GetAppStatusSoapIn" /> 
     <wsdl:output message="tns:GetAppStatusSoapOut" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="MyEcrResponceSoap" type="tns:MyEcrResponceSoap"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
    <wsdl:operation name="Cmd"> 
     <soap:operation soapAction="http://192.168.1.20/Cmd" style="document" /> 
     <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    <wsdl:operation name="GetAppStatus"> 
     <soap:operation soapAction="http://192.168.1.20/GetAppStatus" style="document" /> 
     <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
     <wsdl:output> 
     <soap:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation>  
    </wsdl:binding> 
    <wsdl:service name="MyEcrResponce"> 
    <wsdl:port name="MyEcrResponceSoap" binding="tns:MyEcrResponceSoap"> 
     <soap:address location="http://192.168.1.20/MyEcrResponce/" /> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

ich einen Klienten in C# gemacht habe mit Hilfe von Formularen , ersetzt alle Verweise in Lösung von öffentlicher IP 192.168.1.20 und funktioniert gut:

$client = new SoapClient(
dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MyEcrResponce.wsdl', 
array('location' => 'http://192.168.1.20/MyEcrResponce.cgx', 
    'login' => 'user', 
    'password' => 'pass', 
    'trace' => 0, 
    'cache_wsdl' => WSDL_CACHE_NONE)); 

$cmd = new StdClass(); 
$cmd->CmdText = 'a/'; 

var_dump($client->Cmd($cmd)); 

Egal WHI:

private void button1_Click(object sender, EventArgs e) 
{ 
    string reply = ""; 
    string LcdMsg1 = ""; 
    string LcdMsg2 = ""; 

    Uri ur = new Uri("http://192.168.1.20/MyEcrResponce.cgx"); 

    DeviceWS.MyEcrResponceSoapClient DevHD = new DeviceWS.MyEcrResponceSoapClient(); 
    DevHD.Endpoint.Address = new System.ServiceModel.EndpointAddress(ur); 

    DevHD.ClientCredentials.UserName.UserName = "user"; 
    DevHD.ClientCredentials.UserName.Password = "pass";  

    reply = DevHD.Cmd(CmdTxt.Text, out LcdMsg1, out LcdMsg2); 

    ReplyTxt.Text = reply; 
    LCD01.Text = LcdMsg1; 
    LCD02.Text = LcdMsg2;  
} 

Mein PHP-Client wie folgt aussieht ch kombiniere ich versuche, in PHP bekomme ich immer das letzte Ergebnis von C# client command. Es scheint, dass alle Anfragen mit PHP ignoriert werden. Es scheint, als gäbe es irgendwo einen Cache, den C# überführen kann, aber PHP nicht. In der php.ini sind 'soap.wsdl_cache_enabled' und 'soap.wsdl_cache' auf 0 gesetzt. Ich bekomme das gleiche (fehlerhafte) Verhalten mit SoapUI und anderen SOAP-Testern. Irgendwelche Ideen?

Update 1: PHP $ client -> __ getTypes(); Rückkehr:

array (4) [ 
    string (31) "struct Cmd { 
string CmdText; 
}" 
    string (76) "struct CmdResponse { 
string CmdReply; 
string LcdLine1; 
string LcdLine2; 
}" 
    string (58) "struct GetAppStatus { 
string SerialNo; 
string RetData; 
}" 
    string (82) "struct GetAppStatusResponse { 
unsignedByte GetAppStatusResult; 
string RetData; 
}" 
] 

Update 2: Mit this post I Trace-Protokoll in C# Client aktiviert die Arbeits SOAP-Anforderung zu überprüfen, das ist dieses:

{ 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://192.168.1.20/Cmd" 
Accept-Encoding: gzip, deflate,gzip, deflate 
Authorization: Basic xxxxxxxxxxxxxxxx 
Host: 192.168.1.20 
Content-Length: 207 
Expect: 100-continue 
} 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
     <Cmd xmlns="http://192.168.1.20/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
      <CmdText>a/</CmdText> 
     </Cmd> 
    </s:Body> 
</s:Envelope> 

Leider ist das Ergebnis immer noch das gleiche wenn ich die Anfrage in PHP oder SoapUI kopiere.

Update 3: So, heute ist Montag. Sowohl Kasse als auch PHP-Server wurden am Freitag abgeschaltet und ich habe sie heute geöffnet. Ich löschte alle Cache-Dateien von PHP-Server, BEVOR ich das PHP-Skript ausführen, und ich erhielt die Antwort von der letzten erfolgreichen Befehl, den ich am Freitag gesendet habe !!! Ich bin in der Nähe von dem Punkt, zu glauben, dass ich sehr dumm sein ...

+0

ini_set setzen Versuchen ('soap.wsdl_cache_enabled', '0'); ini_set ('soap.wsdl_cache_ttl', '0'); – WhSol

+0

Ich habe bereits erwähnt, dass der Cache deaktiviert war. – nasos

Antwort

0

Ich schaffte es, zumindest irgendwie mein Problem zu lösen. Ich konnte SOAP-Anfragen nicht korrekt ausführen, aber ich konnte erfolgreich mit Websockets kommunizieren. Ich bestand auf SOAP, weil ich viel mehr Erfahrung habe, aber ich musste aufgeben. Ich wollte etwas sehr Leichtes (ich wollte große Composer-basierte Bibliotheken vermeiden), also fand ich nach einer Menge Suche this post, die ich auf meine Bedürfnisse zugeschnitten hatte und jetzt bekomme ich meine wertvollen Antworten. Für alle anderen, die mit den gleichen oder ähnlichen Problemen konfrontiert sind, benutzt die Registrierkasse RBS-Software (griechische Firma) und Keil-EWeb-Server. Meine modifizierte Arbeits PHP-Code folgt:

class WebsocketClient 
{ 
    private $_Socket = null; 

    public function __construct($host, $port) 
    { 
     $header = "GET/HTTP/1.1\r\n"; 
     $header.= "Host: ".$host.":".$port."\r\n"; 

     $this->_Socket = fsockopen($host, $port, $errno, $errstr, 2); 
     fwrite($this->_Socket, $header) or die('Error: ' . $errno . ':' . $errstr); 
     $response = fread($this->_Socket, 2000); 
    } 

    public function __destruct() 
    { 
     fclose($this->_Socket); 
    } 

    public function sendData($data) 
    { 
     fwrite($this->_Socket, $data) or die('Error:' . $errno . ':' . $errstr); 
     $wsData = fread($this->_Socket, 2000); 
     $retData = trim($wsData,"\x00\xff");   
     return mb_convert_encoding($retData,'utf-8','ISO-8859-7'); // Returns garbage in case of greek (or other letters) 
    } 
} 

$WebSocketClient = new WebsocketClient('192.168.1.20', 9101); 
echo $WebSocketClient->sendData('a/'); 
unset($WebSocketClient); 
0

Try

setzte
ini_set('soap.wsdl_cache_enabled', '0'); 
ini_set('soap.wsdl_cache_ttl', '0'); 

vor Client erstellen.

Ich benutze jetzt NO_CACHE beim Erstellen Client nach einiger Zeit hilft es.

+0

Ich habe bereits erwähnt, dass der Cache deaktiviert war. – nasos