C# 使用.NET使用REST Axis2 WS时无法进行XML序列化

C# 使用.NET使用REST Axis2 WS时无法进行XML序列化,c#,xml,linq,web-services,rest,C#,Xml,Linq,Web Services,Rest,我正在尝试使用C#.NET与RestSharp和Linq一起使用Axis2 REST XML响应。但是,我似乎无法使用RestSharp或手动序列化XML响应 这是来自Axis2的XML响应示例: <ns:response xmlns:ns="http://com.some.where" xmlns:ax2488="http://com.some.where/xsd"> <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema

我正在尝试使用C#.NET与RestSharp和Linq一起使用Axis2 REST XML响应。但是,我似乎无法使用RestSharp或手动序列化XML响应

这是来自Axis2的XML响应示例:

<ns:response xmlns:ns="http://com.some.where" xmlns:ax2488="http://com.some.where/xsd">
<ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax2488:Book">
    <ax2488:field1>Orson Scott Card</ax2488:field1>
    <ax2488:field1>Some One Else</ax2488:field1>
    <ax2488:field2>1</ax2488:field2>
    <ax2488:isbn10>142996393X</ax2488:isbn10>
    <ax2488:isbn13>9781429963930</ax2488:isbn13>
    <ax2488:date>2010</ax2488:date>
    <ax2488:blah>Tom Doherty Associates</ax2488:blah>
    <ax2488:ssss>on loan</ax2488:ssss>
    <ax2488:name>Ender's Game Volume 1 of The Ender Quintet</ax2488:name>
</ns:return>
我尝试了几个不同的元素名称,但没有成功

此外,使用RestSharp,它成功地获得了第一个也是唯一一个响应,但是如果我有多个响应,它将返回null

 var response1 = _client.Execute<Book>(request);
 var response2 = _client.Execute<List<Book>>(request);
var response1=\u client.Execute(请求);
var response2=_client.Execute(请求);

非常感谢您的帮助。

一种可能的方法,将
XDocument
与XPath查询结合使用:

using System.Xml.XPath;

var nsmgr = new XmlNamespaceManager(new NameTable());

//register prefixes for use in XPath
nsmgr.AddNamespace("ns", "http://com.some.where");
nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

var xpath = "//ns:response/ns:return[@xsi:type='ax2488:Book']";
//above xpath consists of path from root to <ns:return> : //ns:response/ns:return
//and criteria for <ns:return> : [@xsi:type='ax2488:Book']

var doc = XDocument.Load("path_to_xml_file.xml");
var returnElements = doc.XPathSelectElements(xpath, nsmgr);
使用System.Xml.XPath;
var nsmgr=newxmlnamespacemanager(newnametable());
//注册前缀以在XPath中使用
nsmgr.AddNamespace(“ns”http://com.some.where");
nsmgr.AddNamespace(“xsi”http://www.w3.org/2001/XMLSchema-instance");
var xpath=“//ns:response/ns:return[@xsi:type='ax2488:Book']”;
//上面的xpath由根目录到://ns:response/ns:return的路径组成
//和标准:[@xsi:type='ax2488:Book']
var doc=XDocument.Load(“path_to_xml_file.xml”);
var returnElements=doc.XPathSelectElements(xpath,nsmgr);
我假设您的XML结构如下所示:

<root>
    <ns:response xmlns:ns="http://com.some.where" xmlns:ax2488="http://com.some.where/xsd">
        <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax2488:Book">
            <ax2488:field1>Orson Scott Card</ax2488:field1>
            <ax2488:field1>Some One Else</ax2488:field1>
            <ax2488:field2>1</ax2488:field2>
            <ax2488:isbn10>142996393X</ax2488:isbn10>
            <ax2488:isbn13>9781429963930</ax2488:isbn13>
            <ax2488:date>2010</ax2488:date>
            <ax2488:blah>Tom Doherty Associates</ax2488:blah>
            <ax2488:ssss>on loan</ax2488:ssss>
            <ax2488:name>Ender's Game Volume 1 of The Ender Quintet</ax2488:name>
        </ns:return>
    </ns:response>
    <ns:response xmlns:ns="http://com.some.where" xmlns:ax2488="http://com.some.where/xsd">
        ........
    </ns:response>
    ........
    ........
</root>

奥森·斯科特·卡德
其他人
1.
142996393X
9781429963930
2010
汤姆·多尔蒂协会
借调
安德的游戏安德五重奏第一卷
........
........
........

从上面的示例XML中,您尝试选择了哪个元素?我在那里看不到任何
元素。我想这根本就是我的问题。
元素是介于
<root>
    <ns:response xmlns:ns="http://com.some.where" xmlns:ax2488="http://com.some.where/xsd">
        <ns:return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax2488:Book">
            <ax2488:field1>Orson Scott Card</ax2488:field1>
            <ax2488:field1>Some One Else</ax2488:field1>
            <ax2488:field2>1</ax2488:field2>
            <ax2488:isbn10>142996393X</ax2488:isbn10>
            <ax2488:isbn13>9781429963930</ax2488:isbn13>
            <ax2488:date>2010</ax2488:date>
            <ax2488:blah>Tom Doherty Associates</ax2488:blah>
            <ax2488:ssss>on loan</ax2488:ssss>
            <ax2488:name>Ender's Game Volume 1 of The Ender Quintet</ax2488:name>
        </ns:return>
    </ns:response>
    <ns:response xmlns:ns="http://com.some.where" xmlns:ax2488="http://com.some.where/xsd">
        ........
    </ns:response>
    ........
    ........
</root>