2013-02-19 51 views
7

如何將soap響應保存到xml?我試着用的TStringList,文件流,創建的XML文件,但我卻得到德爾福肥皂響應保存到XML?

不能轉換型(空)的varinat成(類型(OLESTR)

我想這個簡單的code.The響應不是empty.The文件大小是40MB。Delphi的XE3。

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; 

這是問題(空行)?或不?

... 

- <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 /> 

... 

我試過NullStrictConvert:= False;沒有轉換錯誤,但使用1GB RAM的exe,直到我關閉它。

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

... 
+2

@Lacika你的Delphi的版本是很重要的,斷點是你最好的朋友。 – ComputerSaysNo 2013-02-19 11:49:11

+2

這看起來對我來說是正確的,我們做的事情非常類似於登錄我們的回覆。有時候需要放入一些調試語句,也許是前255個字符的ShowMessage或類似的東西。 – 2013-02-19 13:53:02

+0

我添加了斷點。 xml.savetofile Ok->創建一個文件,打開soap.rio單元,在這一行打破(錯誤):FConverter.ProcessResponse(RespXML,IntfMD,MethMD,Context,FHeadersInbound) – Lacika 2013-02-19 14:01:19

回答

0

嘗試使用流的讀法,以一個臨時字符串變量:

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

謝謝,我明天會試試。 – Lacika 2013-02-19 19:02:29

+0

同樣的問題:( – Lacika 2013-02-20 08:14:28

1

你有沒有嘗試直接傾倒你的流文件,看看裏面有什麼了?

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

Thanks.I明天就試試 – Lacika 2013-02-19 19:01:46

+0

我是爲@kobik建議的,'TFileStream'對於這個意圖更加可讀。[+1] – TLama 2013-02-20 04:05:50

+0

同樣的問題:( – Lacika 2013-02-20 07:50:55

0

奇怪。
也許這個例子有幫助。
我正在做幾乎相同的事情,將響應和請求記錄到TMemo。
另外,我的「前」例行來自外部FSoapData TStringStream填充實際SOAPRequest:

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;