Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq到SQL Web服务XML_C#_Sql Server_Xml_Web Services_Linq To Sql - Fatal编程技术网

C# Linq到SQL Web服务XML

C# Linq到SQL Web服务XML,c#,sql-server,xml,web-services,linq-to-sql,C#,Sql Server,Xml,Web Services,Linq To Sql,我构建了一个连接到SQLServer数据库的.NETWeb服务。有一个web服务调用GetAllQuestions()不会更改。我将GetAllQuestions的结果保存到本地应用程序文件夹中的GetAllQuestions.xml中,并将其设置为content。通常,我会得到如下web服务的结果: var myService = new SATService(); var serviceQuestions = myService.GetAllQuestions(); 我想试试这样的东西:

我构建了一个连接到SQLServer数据库的.NETWeb服务。有一个web服务调用GetAllQuestions()不会更改。我将GetAllQuestions的结果保存到本地应用程序文件夹中的GetAllQuestions.xml中,并将其设置为content。通常,我会得到如下web服务的结果:

var myService = new SATService();
var serviceQuestions = myService.GetAllQuestions();
我想试试这样的东西:

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

任何建议都将不胜感激

GetAllQuestions.xml
很可能包含您并不真正需要的所有SOAP代码——我更喜欢标准的.NET序列化


如果您确实想将原始SOAP消息存储在XML文件中,请尝试。

您不会说您的web服务是ASMX、兼容ASP.NET的WCF还是不兼容ASP.NET的WCF。无论服务是如何托管的,此方法都应获得文件所在的实际物理路径

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到XML、XmlSerializer、XmlReader,甚至是类型化数据集。最好的方法取决于文件的内容,因此您需要向我们提供更多详细信息。

web服务是ASMX。如果将保存为xml的web服务结果自动转换为对象,我会非常高兴。我不明白为什么web服务GetAllQuestions()方法可以立即转换为对象,但当它们完全相同时,xml不能。我真的希望在本地使用web服务结果,就像我在进行远程调用一样。