2013-02-19 5 views
7

Comment est-ce que je peux enregistrer la réponse de savon au xml? J'ai essayé avec TStringList, filestream, a créé le fichier xml mais, mais je suisRéponse au savon Delphi Enregistrer au format xml?

ne pouvait convertir varinat de type (null) dans (type (OLESTR)

J'ai essayé ce simple code.The réponse est non

procedure TForm1.HTTPRIO1AfterExecute(const MethodName: string; 
SOAPResponse: TStream); 
var xml : TStringlist; 
begin 
xml := TStringlist.create; 
    try 
    soapresponse.Position:=0; 
    xml.LoadFromStream(SOAPResponse); 
    xml.SaveToFile('...file.xml'); 
finally 
    xml.Free; 
end; 
end; 

erronée.Le taille du fichier 40Mo. Delphi XE3. c'est le problème (lignes vides)? ou non?

... 

- <leiras> 
- <![CDATA[ 
* Socket AM2 for AMD Athlon™ 64FX/64X2/64 and Sempron processors 
* ULi M1697 

1. Supports FSB 1000MHz (2.0GT/s), Hyper-Transport Technology and AMD Cool 'n' Quiet Technology 
2. Untied Overclocking : During Overclocking, FSB enjoys better margin due to fixed PCIE/ PCI Buses 
3. Supports Dual Channel DDRII800/667/533, 4 x DIMM slots, with maximum capacity up to 8GB 
4. Hybrid Booster - ASRock Safe Overclocking Technology 
5. Supports Dual Graphics XLI 
6. 1 x PCI Express x16 slot 
7. 1 x PCI Express x 8 slot, to adopt 2nd PCI Express x 16 VGA card and other PCI Express x4, x2, x1 interface cards 
8. 2 x PCI Express x1 slots 
9. 4 x Serial ATA II 3.0Gb/s, support RAID (RAID 0, 1, 0+1, JBOD and RAID 5), NCQ, AHCI and "Hot Plug" functions 
10. 2 x eSATAII 3.0Gb/s, support NCQ, AHCI and "Hot Plug" functions 
11. HDMI_SPDIF header, providing SPDIF audio output to HDMI VGA card, allows the system to connect HDMI Digital TV/projector/LCD devices. 
12. 7.1 Channel with High Definition Audio 
13. Windows Vista™ Premium Logo Hardware Ready 
14. ASRock 8CH_eSATAII I/O: 2 eSATAII ports, HD 7.1 channel audio jacks 


]]> 
</leiras> 
<kepek /> 

... 

J'ai essayé NullStrictConvert: = False; pas d'erreur de conversion, mais l'exe en utilisant 1 Go de RAM, jusqu'à ce que je le ferme.

... 
var xml : TStringlist; 
begin 
xml := TStringlist.create; 
NullStrictConvert := False; 
try 
    soapresponse.Position:=0; 

... 
+2

@Lacika votre version delphi est important, points d'arrêt sont vos meilleurs amis. – ComputerSaysNo

+2

Cela me semble correct, nous faisons quelque chose de très similaire à enregistrer nos réponses. Il est temps de mettre des instructions de débogage, peut-être un ShowMessage sur les 255 premiers caractères ou quelque chose comme ça. –

+0

j'ai ajouté le point d'arrêt. xml.savetofile Ok-> a créé un fichier, ouvre l'unité soap.rio, casse (erreur) sur cette ligne: FConverter.ProcessResponse (RespXML, IntfMD, MethMD, Contexte, FHeadersInbound) – Lacika

Répondre

0

Essayez d'utiliser la méthode de flux lecture à une variable chaîne temporaire:

procedure TForm1.HTTPRIO1AfterExecute(const MethodName: string; SOAPResponse: TStream); 
var 
    s: string[200]; 
    ds: string; 
    n: Longint; 
    xml: TStringList; 
begin 
    SOAPResponse.Position := 0; 
    xml := TStringList.Create; 
    try 
    ds := EmptyStr; 
    while SOAPResponse.Position < SOAPResponse.Size do begin 
     n := SOAPResponse.Read(s[1], 200); 
     SetLength(s, n); 
     xml.Text := xml.Text + ds; 
    end; 

    xml.SaveToFile('...file.xml'); 
    finally 
    xml.Free; 
    end; 
end; 
+0

Merci. Je vais essayer demain. – Lacika

+0

même problème :( – Lacika

1

Avez-vous essayer de mettre votre flux directement dans un fichier, pour voir ce qui est là-dedans?

procedure TForm1.HTTPRIO1AfterExecute(const MethodName: string; SOAPResponse: TStream); 
var 
    FS: TFileStream; 
begin 
    FS := TFileStream.Create('C:\Downloaded.xml', fmCreate); 
    try 
    FS.CopyFrom(SoapResponse, 0); 
    finally 
    FS.Free; 
    end; 
end; 
+0

Merci.I va essayer demain – Lacika

+0

Je suis pour ce que @kobik suggère, 'TFileStream' est encore plus lisible pour cette intention. [+1] – TLama

+0

même problème :( – Lacika

0

Bizarre.
Peut-être que cet exemple est utile.
Je fais presque la même chose, en enregistrant la réponse et la demande à un TMemo.
Aussi, mon 'avant' la routine remplit la SOAPRequest réelle d'un FSoapData externe TStringStream:

procedure TFrmTestEWS.HTTPRIOBeforeExecute(const MethodName: string; SOAPRequest: TStream); 
var 
    TS: TStringStream; 
    S : String; 
begin 
    // 1. Fill request 
    SOAPRequest.Position := 0; 
    FSoapData.Position := 0; 
    SOAPRequest.CopyFrom(FSoapData,FSoapData.Size); 
    SOAPRequest.Size := FSoapData.Size; 
    // 2. Logging 
    S := 'Request:' + #13#10#13#10; 
    TS := TStringStream.Create(S); 
    try 
     TS.Position := Length(S); 
     FSoapData.Position := 0; 
     TS.CopyFrom(FSoapData,FSoapData.Size); 
     TS.Position := 0; 
     MmoLog.Lines.LoadFromStream(TS); 
    finally 
     TS.Free; 
    end; 
end; 

procedure TFrmTestEWS.HTTPRIOAfterExecute(const MethodName: string; SOAPResponse: TStream); 
var 
    TS: TStringStream; 
    S : String; 
begin 
    S := MmoLog.Text + #13#10#13#10 + 'Response:' + #13#10#13#10; 
    TS := TStringStream.Create(S); 
    try 
     TS.Position := Length(S); 
     SOAPResponse.Position := 0; 
     TS.CopyFrom(SOAPResponse,SOAPResponse.Size); 
     TS.Position := 0; 
     MmoLog.Lines.LoadFromStream(TS); 
    finally 
     SOAPResponse.Position := 0; 
     TS.Free; 
    end; 
end; 
Questions connexes