开发者

Linq to SQL Web Service XML

I built a .NET web service connecting to an SQL Server database. There is a web service call GetAllQuestions() that will not change. I saved the result of GetAllQuestions to GetAllQuestions.xml in the local application folder and set it to content. Normally I would get the开发者_如何学编程 result of the web service like this:

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

I want to try something like:

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

Any suggestions are much appreciated!


GetAllQuestions.xml most likely contains all that SOAP cruft you don't really need -- I'd prefer standard .NET serialization.

If you really want to store raw SOAP message in an XML file, try this.


You don't say whether your web service is ASMX, WCF with ASP.NET compatibility, or WCF without ASP.NET compatibility. This method should get you the real physical path in which your file resides regardless of how your service is hosted.

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);
    }
}

Once you have located the file, you now need to consider how best to read its content. You have various options, e.g. LINQ to XML, XmlSerializer, XmlReader or even a typed DataSet. The best method depends on the content of the file, so you need to give us more detail on that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜