2010-03-31 194 views
0

我構建了一個連接到SQL Server數據庫的.NET Web服務。有一個Web服務調用GetAllQuestions()不會改變。我將GetAllQuestions的結果保存到本地應用程序文件夾中的GetAllQuestions.xml中,並將其設置爲內容。通常我會得到這樣的Web服務的結果:Linq to SQL Web服務XML

var myService = new SATService(); 
var serviceQuestions = myService.GetAllQuestions(); 

我想嘗試類似:

var serviceQuestions = File.Open("GetAllQuestions.xml"); 

任何建議都非常感謝!

回答

0

GetAllQuestions.xml最有可能包含所有你不真正需要的SOAP cruft - 我更喜歡標準的.NET序列化。

如果您確實想將原始SOAP消息存儲在XML文件中,請嘗試this

+0

我真的很想在本地使用Web服務結果,就像我在進行遠程調用一樣。 – Bryan 2010-04-03 06:41:01

0

你不會說你的web服務是ASMX,WCF與ASP.NET兼容還是WCF沒有ASP.NET兼容性。無論您的服務託管方式如何,此方法都會爲您提供文件所在的真實物理路徑。

string GetContentFilePath() { 
    if(HttpRuntime.AppDomainAppVirtualPath != null) { 
     // HTTP runtime is present, so the content file is in the virtual directory. 
     return HttpRuntime.AppDomainAppPath; 
    } else { 
     // HTTP runtime is not present, so the content file is in the same directory as the assembly. 
     return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 
    } 
} 

找到文件後,您現在需要考慮如何最好地閱讀其內容。您有各種選擇,例如LINQ to XML,XmlSerializer,XmlReader甚至是一個類型化的DataSet。最好的方法取決於文件的內容,所以你需要給我們更多的細節。

+0

Web服務是ASMX。如果保存爲xml的Web服務結果自動轉換爲對象,我會喜歡它。我不明白爲什麼web服務的GetAllQuestions()方法可以立即轉化爲對象,但是當xml完全相同時,xml不能。 – Bryan 2010-04-03 03:54:18