2010-03-31 183 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