views:

42

answers:

2

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!

A: 

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.

Anton Gogolev
I would really like to use the web service result locally exactly like I was making a remote call.
Bryan
A: 

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.

Christian Hayter
The web service is ASMX. I would love it if the web service result saved as xml was automatically converted to objects. I don't understand why the web service GetAllQuestions() method can be turned into objects instantly, but the xml cannot when they are the exact same thing.
Bryan